perf: stop allocating a warnings array for a clean compile - #49
Open
msallin wants to merge 1 commit into
Open
Conversation
msallin
force-pushed
the
perf/empty-warnings-no-alloc
branch
from
September 6, 2026 19:51
0db86b4 to
10b0464
Compare
Every document allocated a string array even when the compiler reported no warnings, which is the common case. Array.Empty covers it without allocating. Array.AsReadOnly already returns the shared empty collection for a zero-length array, so the wrapper it is passed to costs nothing either way.
msallin
force-pushed
the
perf/empty-warnings-no-alloc
branch
from
September 6, 2026 19:55
10b0464 to
90b9c6e
Compare
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]even when the compiler reported no warnings, which is the common case.Array.Empty<string>()covers it without allocating.Scope, stated plainly: this saves 24 bytes per warning-free compile, and nothing else.
Array.AsReadOnlyhas returned the shared empty collection for a zero-length array since .NET 8, so the wrapper it is passed to was already free. Against a compile that takes milliseconds and allocates megabytes of native memory, this is below noise — it is here because it is one line and free, not because it is measurable.The test covers the warning-free case, which had none. It pins the public contract rather than the allocation, so it passes on
developtoo; it is coverage, not a regression guard.57/57 pass, clean on net8/9/10.