Skip to content

perf: stop allocating a warnings array for a clean compile - #49

Open
msallin wants to merge 1 commit into
evolvedlight:developfrom
swisspost:perf/empty-warnings-no-alloc
Open

perf: stop allocating a warnings array for a clean compile#49
msallin wants to merge 1 commit into
evolvedlight:developfrom
swisspost:perf/empty-warnings-no-alloc

Conversation

@msallin

@msallin msallin commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Every TypstDocument allocated new 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.AsReadOnly has 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 develop too; it is coverage, not a regression guard.

57/57 pass, clean on net8/9/10.

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
msallin force-pushed the perf/empty-warnings-no-alloc branch from 10b0464 to 90b9c6e Compare September 6, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant