Commit 7df0439
feat: cache common
Add `StringDoc.Create` to reuse common `StringDoc` types where possible.
Saving 1.7 MB, 2% of memory usage.
### Most common `StringDoc` types (total 97,000)

- I did most of the common single character symbols, it might be worth
adding other common symbols like `int`, `string`, `true`, `var`, `new`
etc. The switch statements of this size are lowered into an efficient
hash/binary tree so I doubt it makes a meaningful performance impact.
- Is it worth exploring caching all new `StringDoc` types? There are a
total of 674 unique `StringDoc` symbols in the example benchmark, I
wonder how many unique symbols are in a real world 1M loc project.
Perhaps a cache for each file or using a static `ConditionalWeakTable`.
I can see this causing a memory leak if implemented incorrectly😅
- A future change could look into creating a `SpanDoc` type that
contains `SyntaxToken.Span`, this is used to copy the relevant section
of the original code into the new text without allocating.
Co-authored-by: Bela VanderVoort <[email protected]>StringDoc types (#1494)1 parent 2f6094c commit 7df0439
File tree
3 files changed
+467
-5
lines changed- Src/CSharpier
- DocTypes
- SyntaxPrinter
3 files changed
+467
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
0 commit comments