perf: stop allocating a warnings array for a clean compile - #6
Closed
msallin wants to merge 1 commit into
Closed
Conversation
msallin
force-pushed
the
perf/empty-warnings-no-alloc
branch
from
September 6, 2026 19:09
332809d to
91b28e4
Compare
Every document allocated a string array and wrapped it with Array.AsReadOnly, including the common case of no warnings at all, where both are 24 bytes of pure ceremony. The shared empty collection covers that case without allocating and keeps Warnings immutable, which a caller-facing list has to stay.
msallin
force-pushed
the
perf/empty-warnings-no-alloc
branch
from
September 6, 2026 19:16
91b28e4 to
e6e208e
Compare
Member
Author
|
Reopened upstream against the parent repository: evolvedlight#49 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
TypstDocumentallocatednew string[warningCount]and wrapped it withArray.AsReadOnly, including when there are no warnings at all, which is the common case.Measured: the zero-length array is 24 bytes and the wrapper another 24.
ReadOnlyCollection<string>.Emptyallocates nothing. 48 bytes per document, small on its own, but free and on the path every compile takes including the zero-copy one.WarningsstaysIReadOnlyList<string>and stays immutable, which the existingWarningsFromADocumentCannotBeMutatedByCallerstest pins.ReadOnlyCollection<T>.Emptyis available from net8, so all three target frameworks are covered.Tests
WarningsFromACleanCompileAreEmptyAndStillImmutablecovers the branch that previously had none: empty, enumerable, not a rawstring[], and still readable after the document is disposed.57/57 tests pass. Builds clean on net8, net9 and net10 with zero warnings.