Skip to content

Preserve noninterned string constant identity - #630

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/string-reference-identity-independent
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/string-reference-identity-independent

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

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.

Runtime TestX groups Legacy tests
.NET 10 495 passed 1,756 passed
.NET 8 495 passed 1,755 passed
.NET Framework 4.7.2 474 passed 1,639 passed

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)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 1243.4 → 1234.8 2.3 → 3.2 872.0 → 872.0 0.0 → 0.0
Standard / string_literal 1150.6 → 1216.4 2.0 → 2.0 864.1 → 864.1 0.0 → 0.0
Standard / string_fresh 935.2 → 1263.1 2.0 → 2.0 864.0 → 984.0 0.0 → 0.0
Standard / string_length 1010.0 → 1012.9 2.0 → 2.0 896.0 → 864.0 0.0 → 0.0
Light / add_control 1011.5 → 1042.8 2.0 → 2.0 872.0 → 872.0 0.0 → 0.0
Light / string_literal 810.4 → 885.8 1.9 → 2.0 864.0 → 864.0 0.0 → 0.0
Light / string_fresh 750.7 → 1112.9 1.9 → 2.0 864.0 → 984.0 0.0 → 0.0
Light / string_length 1111.5 → 862.2 2.0 → 2.0 896.0 → 864.0 0.0 → 0.0
net10.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 4883.0 → 3615.1 1.9 → 2.0 872.0 → 872.0 0.0 → 0.0
Standard / string_literal 2516.2 → 2519.0 2.0 → 2.0 864.0 → 864.0 0.0 → 0.0
Standard / string_fresh 2484.4 → 2861.4 2.0 → 2.0 864.0 → 984.0 0.0 → 0.0
Standard / string_length 2766.3 → 2458.6 2.0 → 2.0 896.0 → 864.0 0.0 → 0.0
Light / add_control 2572.2 → 2575.2 2.0 → 2.0 872.0 → 872.0 0.0 → 0.0
Light / string_literal 2437.7 → 2719.6 2.0 → 2.0 864.0 → 864.0 0.0 → 0.0
Light / string_fresh 2188.9 → 2630.2 2.0 → 2.0 864.0 → 984.0 0.0 → 0.0
Light / string_length 2459.3 → 2090.3 2.0 → 1.9 896.0 → 864.0 0.0 → 0.0

Emitted IL differs in these measured workloads: string_fresh, string_length.
Light / string_fresh compile allocation: 120 B/op more than master.
Standard / string_fresh compile allocation: 120 B/op more than master.
Light / string_length compile allocation: 32 B/op less than master.
Standard / string_length compile allocation: 32 B/op less than master.

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.
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