-
-
Notifications
You must be signed in to change notification settings - Fork 111
perf: remove CodeWriter bad initialisation
#4585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
SummaryRemoves unnecessary pre-seeding of the static indent cache in CodeWriter constructor. Critical IssuesNone found ✅ SuggestionsNone - this is a good optimization. Analysis: The removed code was pre-seeding a static readonly ConcurrentDictionary with 10 entries on every CodeWriter instantiation. Since the cache is static and shared across all instances, most of these TryAdd calls would fail after the first instance. The GetIndentation method (line 54-58) already handles lazy initialization via GetOrAdd, making this pre-seeding redundant. This removes allocations from the source generator hot path (10 Enumerable.RepeatIterator + 10 strings per constructor call). Verdict✅ APPROVE - Valid performance optimization with no behavioral changes. |
|
Ran the benchmarks and this saves 10MB Before (timing is inaccurate, laptop not plugged in and ran once.
After
|
Each time
CiodeWriteris intialised it will try to pre seed_indentCachewith different length strings.indentStringEnumerable.RepeatIteratorandstringmaking this an anti optimisation