Skip to content

Preserve boxed storage for writable Unbox expressions - #608

Merged
dadhi merged 2 commits into
dadhi:masterfrom
jogibear9988:fix/unbox-storage-standalone
Nov 9, 2026
Merged

dadhi merged 2 commits into
dadhi:masterfrom
jogibear9988:fix/unbox-storage-standalone

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Mutating a struct through Unbox can update a temporary instead of the boxed value. Emit an unbox address for writable storage contexts and ref arguments, while preserving value copies for ordinary reads and Convert, plus nullable/null/type-check behavior.

Validation

The focused regression reproduces a failure or crash on master a0950432 and passes with this change. Release solution build passes with zero warnings/errors. Both Standard and LightExpression native suites run.

Runtime TestX passed Legacy passed
.NET 10 363 1,756
.NET 8 363 1,755
.NET Framework 4.7.2 344 1,639

Measurements

Compare master a0950432 with this commit 8f66d7ac. Windows ARM64, Release; .NET 8.0.28 and 10.0.9. Compilation uses prebuilt trees; invocation uses precompiled delegates and excludes expression construction/compilation. Standard and LightExpression are measured separately.

Two fresh process rounds reverse version-loading order, pin execution to one logical CPU, disable tiered compilation, warm both versions, and alternate measurement order. Values below are medians across 14 samples per side (seven per round; 30 ms calibration target).

Compilation allocation changes on the listed affected controls: -8 B/op. Other measured compilation allocations match master. Invocation allocations match master on every control. Delegate IL changes on unbox_read; the other control IL matches master.

Identical-master control runs also varied: compilation -15.2% to +23.4%, invocation -21.5% to +8.9%. Timings below are observations, not a speedup or universal performance-neutrality claim. Cases that fail or produce invalid IL on master have no meaningful before/after invocation ratio; the table uses executable controls that return the expected result in both versions. Framework correctness is tested above; its performance is not measured here.

All table pairs are master → this change. B/op is allocated bytes per operation.

.NET / API Control Compile ns/op Compile B/op Invoke ns/op Invoke B/op
10 / Light add_control 2,521 → 2,515 872 → 872 1.94 → 1.99 0 → 0
10 / Light convert_copy 2,875 → 2,782 936 → 936 2.20 → 2.17 0 → 0
10 / Light unbox_read 3,048 → 3,585 936 → 928 2.19 → 2.24 0 → 0
10 / Standard add_control 3,260 → 3,110 872 → 872 1.91 → 1.92 0 → 0
10 / Standard convert_copy 6,597 → 4,208 936 → 936 2.30 → 2.29 0 → 0
10 / Standard unbox_read 3,282 → 3,322 936 → 928 2.26 → 2.24 0 → 0
8 / Light add_control 990 → 990 872 → 872 1.97 → 2.02 0 → 0
8 / Light convert_copy 1,001 → 1,109 936 → 936 2.39 → 2.21 0 → 0
8 / Light unbox_read 1,050 → 1,034 936 → 928 2.22 → 2.23 0 → 0
8 / Standard add_control 1,019 → 1,030 872 → 872 1.93 → 1.94 0 → 0
8 / Standard convert_copy 1,126 → 1,314 936 → 936 2.20 → 2.26 0 → 0
8 / Standard unbox_read 1,163 → 1,143 936 → 928 2.26 → 2.31 0 → 0

Use unbox addresses for nonnullable writable receivers and ref arguments; retain unbox.any for ordinary values and nullable unboxing. Keep Convert copy semantics, nullable temporaries and null/type checks.
@jogibear9988
jogibear9988 force-pushed the fix/unbox-storage-standalone branch from 8f66d7a to 472adbd Compare November 9, 2026 22:22
@dadhi
dadhi merged commit fa2622c into dadhi:master Nov 9, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/unbox-storage-standalone branch November 9, 2026 23:18
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.

2 participants