Repository navigation
Compile dynamic call sites with per-occurrence state - #675
jogibear9988 wants to merge 3 commits into
Conversation
Runtime expression invocation must follow System’s structural stack-spill ordering even when FEC prunes a dead try or goto branch. Inspect argument syntax without reducing opaque extension nodes, and defer the implicit Compile call where required. Tests compare result, exception and side-effect order for valid, null and invalid receivers, including dead conditional branches.
Record structural spill information during normal argument collection and inspect only discarded conditional/switch syntax with an iterative cursor stack. Preserve lambda/quote boundaries and keep emitted region metadata separate. Use child cursors and an inline buffer to avoid wide sibling queues, advance unary chains in place, and bypass the cursor frame for simple discarded nodes. Keep the original ordering regressions and add deep/wide syntax, initializer, boundary and extension coverage. Validation: full Release build; Standard and LightExpression suites on net8.0, net10.0 and net472; fresh compile/runtime/allocation comparisons against master and the previous PR head. Shared delegates retain identical emitted IL.
Lower dynamic nodes to CallSite operations, preserving per-occurrence state, mutable targets, evaluation order and ref copyback. Preserve quoted nodes as data and avoid deduplicating stateful nested lambdas. Reuse structural spill tracking from the parent change instead of a recursive argument visitor. Build call-site operations directly in either expression API, preserving original LightExpression arguments without a System conversion round-trip. Validation: full Release build and Standard/LightExpression suites on net8.0, net10.0 and net472. Fresh compile/runtime comparisons include the parent, previous feature head and working dynamic case. Measured dynamic compilation saves 24 B for System-expression inputs and 504 B for LightExpression; runtime remains allocation-free in that case.
b06035d to
9b8c52c
Compare
|
This PR had the same recursive visitor / repeated argument walk discussed in #665. It is now rebuilt on #665 (parent e95d0ff), with the dynamic feature in 9b8c52c. The branch was updated with an explicit force-with-lease check against the previous head. Dynamic target ordering now reuses the collector's structural spill tracking and iterative inspection of discarded syntax. The visitor is removed. LightExpression call-site lowering also uses the original argument nodes directly, eliminating the Light → System → Light round-trip. Existing occurrence/state, target mutation, exception and ref-copyback tests remain. Full Release build and Standard/LightExpression suites pass on .NET 8, .NET 10 and net472, including the inherited deep/wide regressions. Fresh measurements of the working dynamic case show:
Runtime remains 0 B/op; emitted IL for this measured dynamic case is unchanged. Shared controls add no allocation over #665. All runtime timings, slower observations, and the comparison with the #665 base are in the updated description. The PR stays in dadhi's repo and targets master; its description links #665 as a dependency and provides the incremental diff, so the parent should merge first. |
Stacked on #665 (
e95d0ffcf5bc4b33c5ea419f16d39bbb8532613c). Incremental diff over #665. The PR continues to target upstream master until the parent merges.Compile dynamic expressions as intrinsic CallSite operations, preserving separate emitted occurrences, mutable targets, argument order, typed/void results and ref copyback. Stateful nested lambdas keep separate call sites; quoted dynamic nodes remain data.
Dynamic collection reuses #665’s structural spill tracking. The recursive visitor and its additional argument walk are removed. LightExpression lowering now builds the call-site operations directly from the original argument nodes instead of converting Light → System → Light.
Validation
Full Release solution build and Standard/LightExpression native suites pass for net8.0, net10.0 and net472. Dynamic regressions cover rebinding, reused nodes/nested lambdas, target replacement, exceptions, typed/void returns, ref aliases and property writeback. The inherited deep/wide and ordering regressions from #665 also pass.
Measurements
Fresh measurements use the #665 base
e95d0ffcf5bc4b33c5ea419f16d39bbb8532613c, old #675b06035d7cae72c827447d3c6ed166512bb51c8f6, and revised #6759b8c52c7487503c4fa02870445942038dcbfdac0. SDK 10.0.301; Windows ARM64; task-local runtimes 8.0.28 and 10.0.9.Both input APIs use FEC. Trees/conversions/adapters are prepared before measurement; compilation includes delegate creation. Two opposite-load-order process runs, seven rotated samples each, medians of 14 samples. Tiering disabled; one fixed logical CPU; GC.GetAllocatedBytesForCurrentThread. Calibration targets 150 ms across the three shared variants and 100 ms across the two dynamic variants. Runtime expression invocation includes uncached System Compile; dynamic runtime figures use a warmed call site and exclude first binder compilation.
The #665-base comparison isolates this feature’s additional cost; the old #675 comparison includes the traversal/lowering rework and inherited #665 changes. All slower observations are retained. Timing variation prevents a blanket speedup or no-regression claim.
In the working dynamic case, compilation allocation drops by 24 B for System-expression inputs and 504 B for LightExpression on both runtimes. Light compilation measured 4.862 → 2.722 μs on .NET 8 and 4.643 → 2.852 μs on .NET 10. Runtime allocations remain 0 B/op. Shared controls add no allocation over the #665 base.
Working dynamic case
Values are old #675 → revised #675.
fixed_caseis a typed dynamic call returning 7 through a constant binder. #665 alone does not support this case.Shared compilation and runtime controls
Values are #665 base → old #675 → revised #675.
nested_lambdaruntime_expression_dead_switchruntime_expression_dead_tryruntime_expression_deep_dead_plainruntime_expression_deep_dead_tryruntime_expression_live_addruntime_expression_plainruntime_expression_wide_dead_plainscalar_addnested_lambdaruntime_expression_dead_switchruntime_expression_dead_tryruntime_expression_deep_dead_plainruntime_expression_deep_dead_tryruntime_expression_live_addruntime_expression_plainruntime_expression_wide_dead_plainscalar_addnested_lambdaruntime_expression_dead_switchruntime_expression_dead_tryruntime_expression_deep_dead_plainruntime_expression_deep_dead_tryruntime_expression_live_addruntime_expression_plainruntime_expression_wide_dead_plainscalar_addnested_lambdaruntime_expression_dead_switchruntime_expression_dead_tryruntime_expression_deep_dead_plainruntime_expression_deep_dead_tryruntime_expression_live_addruntime_expression_plainruntime_expression_wide_dead_plainscalar_addEmitted IL for shared controls: identical between the compared revisions.
Emitted IL for working dynamic case: identical between the compared revisions.