Repository navigation
Preserve noninterned string constant identity - #630
Open
jogibear9988 wants to merge 1 commit into
Open
jogibear9988 wants to merge 1 commit into
jogibear9988 wants to merge 1 commit into
Conversation
Emitting a fresh string constant with ldstr substitutes the interned object and loses reference identity. Capture noninterned strings in the existing closure; retain ldstr for the original interned string and metadata literal fields. Closure-free compilation returns null when it cannot preserve the supplied reference. Fold Length of a known non-null string during collection and emission so identity-unobservable length reads need no capture. Validation: Release solution build; full Standard and LightExpression .NET 8, .NET 10 and Framework runners pass. Measurements: master 094d067 versus this change, compilation and invocation, both APIs, .NET 8/10, two opposite-order process rounds with seven samples each. Measured allocation increases: string_fresh compile: 120 B/op. Timings and emitted IL are recorded in the PR description; these controls do not establish universal performance neutrality.
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.
Emitting a fresh string constant with ldstr substitutes the interned object and loses reference identity. Capture noninterned strings in the existing closure; retain ldstr for the original interned string and metadata literal fields. Closure-free compilation returns null when it cannot preserve the supplied reference. Fold Length of a known non-null string during collection and emission so identity-unobservable length reads need no capture.
Declared string/object/interface constants, distinct equal strings, nested lambdas, supplied closures and literal fields. Identity is checked with the System interpreter and identity-preserving compiled controls because System IL compilation also interns string constants. Noninterned strings require capture storage, so increased compilation allocation is a correctness cost. Known lengths and ignored constant-length reads are also checked with closure-free compilation; null length receivers still throw. In these measurements, returning a fresh string costs 120 B more per compilation; known constant-length reads save 32 B. Both APIs and runtimes show these changes, with invocation allocation unchanged. Regressions require strict FEC compilation. Native suites cover Standard and LightExpression.
Validation
Local validation uses master baseline 094d067 plus this change. Release solution build: zero warnings/errors.
Measurements
Master baseline
094d0678→ this change, Release, Windows ARM64, .NET 8.0.28 / 10.0.9. Compilation uses prebuilt trees; runtime measures invocation through the same wrapper. Two fresh process rounds with reversed load order, seven samples per round, about 30 ms calibration, one logical CPU and tiered compilation disabled. Tables use the median of the two per-round medians.The controls below produce correct results on master for their measured inputs. Newly supported trees have no valid before/after execution comparison because master rejects them, produces incorrect results or emits invalid IL. Timings include machine and JIT/code-placement variation; the unchanged add control helps show that variation. These observations do not prove universal performance neutrality.
net8.0 results (master → change)
net10.0 results (master → change)
Emitted IL differs in these measured workloads:
string_fresh,string_length.Light / string_freshcompile allocation: 120 B/op more than master.Standard / string_freshcompile allocation: 120 B/op more than master.Light / string_lengthcompile allocation: 32 B/op less than master.Standard / string_lengthcompile allocation: 32 B/op less than master.