Skip to content

Invoke runtime expression values with ref arguments - #663

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/runtime-expression-ref-arguments-20261114
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/runtime-expression-ref-arguments-20261114

Conversation

@jogibear9988

@jogibear9988 jogibear9988 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Extend runtime Expression invocation to ref storage and property/indexer copyback. Compile the receiver once per invocation, preserve operand ordering, and copy property temporaries back only after successful completion.

Tests cover parameter/array addresses, getter/setter counts, exceptions, protected arguments and compilation flags. System loses property copyback for the protected-argument shape; that case uses an explicit temporary/writeback control.

Validation

Full Release solution build and Standard/LightExpression native runners pass for net8.0, net10.0 and net472. net8.0: 688 TestX and 1744 legacy cases; net10.0: 688 TestX and 1745 legacy cases; net472: 669 TestX and 1610 legacy cases.

Measurements

FEC on master da14580f10fd19ae2361a8e91cfad4b2dfec182a → this change e527f33e56b6e2cd51c64555613d1826163e07d8. Windows ARM64; .NET 8.0.28 and 10.0.9; SDK 10.0.301.

Trees, API conversions and invocation adapters are built before measurement. Compilation includes delegate creation; runtime measures the compiled delegate through the same adapter. Both sides are FEC: “System trees” names the expression API, not the System compiler.

Two opposite-load-order process rounds; seven alternating paired samples per round; medians of 14 samples, 100 ms calibration target. Verified task-local runtimes; tiered compilation disabled; each process pinned to one logical CPU. Allocations use GC.GetAllocatedBytesForCurrentThread. Slower observations are retained. Timing variation, including unchanged IL controls, prevents a blanket speedup or no-regression claim.

Runtime / API Workload Compile μs, master → patch Compile B/op Runtime ns, master → patch Runtime B/op
net10.0 / LightExpression delegate_invoke 5.089 → 4.579 1000.0 2.855 → 2.694 0.0
net10.0 / LightExpression ref_call 4.920 → 5.838 928.0 3.714 → 3.393 0.0
net10.0 / LightExpression runtime_expression_plain 15.119 → 10.826 1568.0 40777.467 → 46038.596 4256.1
net10.0 / LightExpression scalar_add 5.376 → 6.067 872.0 2.598 → 2.749 0.0
net10.0 / System trees delegate_invoke 11.034 → 12.196 1000.0 3.392 → 3.056 0.0
net10.0 / System trees ref_call 6.282 → 5.711 928.0 4.151 → 4.019 0.0
net10.0 / System trees runtime_expression_plain 17.694 → 17.001 1568.0 72137.402 → 55384.591 4256.3
net10.0 / System trees scalar_add 4.564 → 5.400 872.0 2.463 → 2.331 0.0
net8.0 / LightExpression delegate_invoke 17.732 → 14.563 1000.0 7.181 → 9.065 0.0
net8.0 / LightExpression ref_call 7.901 → 9.675 928.0 4.897 → 6.090 0.0
net8.0 / LightExpression runtime_expression_plain 10.726 → 10.883 1568.0 34709.390 → 35785.319 4256.1
net8.0 / LightExpression scalar_add 7.698 → 5.514 872.0 9.555 → 7.798 0.0
net8.0 / System trees delegate_invoke 12.390 → 11.574 1000.0 5.796 → 5.616 0.0
net8.0 / System trees ref_call 8.736 → 9.224 928.0 4.223 → 3.586 0.0
net8.0 / System trees runtime_expression_plain 33.424 → 24.833 1568.0 80741.069 → 66224.318 4256.4
net8.0 / System trees scalar_add 7.480 → 6.327 872.0 4.141 → 5.300 0.0

Shared-workload emitted IL is unchanged.

Allocation changes: none beyond measurement rounding in these shared workloads.

Affected cases without a valid master baseline

Master rejects these trees or generates a delegate with incorrect behavior, so they are excluded from comparative timings. Patch-only measurements use 14 samples, a 30 ms calibration target, and the same compilation/runtime separation. fixed_case exercises this PR’s added behavior.

Runtime / API Case Compile μs Compile B/op Runtime ns Runtime B/op
net10.0 / LightExpression fixed_case 37.620 1640.2 89188.281 4402.6
net10.0 / System trees fixed_case 39.058 1653.2 596850.000 4568.0
net8.0 / LightExpression fixed_case 65.650 1800.0 156666.667 4401.7
net8.0 / System trees fixed_case 30.168 1641.6 117781.395 4400.3

The affected runtime invocation includes System Compile on every call; it does not cache the compiled expression.

Extend runtime Expression<TDelegate> invocation to ref storage and property/indexer copyback. Compile the receiver once per invocation, preserve operand ordering, and copy property temporaries back only after successful completion.

Tests cover parameter/array addresses, getter/setter counts, exceptions, protected arguments and compilation flags. System loses property copyback for the protected-argument shape; that case uses an explicit temporary/writeback control.
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