Skip to content

Preserve runtime numeric switch-case evaluation - #605

Merged
dadhi merged 2 commits into
dadhi:masterfrom
jogibear9988:fix/runtime-switch-tests-standalone
Nov 9, 2026
Merged

dadhi merged 2 commits into
dadhi:masterfrom
jogibear9988:fix/runtime-switch-tests-standalone

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Numeric switch cases evaluated at runtime are rejected, and constant-input folding can skip an earlier runtime-dependent case and its effects. Use ordered comparisons when a numeric case cannot use the constant table; stop folding before runtime-dependent tests.

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 359 1,756
.NET 8 359 1,755
.NET Framework 4.7.2 340 1,639

Measurements

Compare master a0950432 with this commit c62a22c4. 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).

Measured compilation and invocation allocations match master on every control. Control delegate 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 4,001 → 4,146 872 → 872 2.66 → 2.64 0 → 0
10 / Light constant_switch 5,648 → 5,449 1104 → 1104 3.30 → 3.19 0 → 0
10 / Light string_runtime_switch 5,268 → 5,349 1176 → 1176 3.32 → 3.39 0 → 0
10 / Standard add_control 4,065 → 4,046 872 → 872 2.48 → 2.91 0 → 0
10 / Standard constant_switch 7,072 → 8,542 1104 → 1104 3.09 → 3.17 0 → 0
10 / Standard string_runtime_switch 9,753 → 8,070 1232 → 1232 3.81 → 3.76 0 → 0
8 / Light add_control 1,482 → 1,643 872 → 872 2.95 → 2.82 0 → 0
8 / Light constant_switch 2,581 → 2,347 1104 → 1104 3.30 → 3.96 0 → 0
8 / Light string_runtime_switch 3,045 → 2,928 1176 → 1176 5.01 → 4.44 0 → 0
8 / Standard add_control 2,514 → 2,793 872 → 872 3.80 → 3.68 0 → 0
8 / Standard constant_switch 3,289 → 3,249 1104 → 1104 3.17 → 3.10 0 → 0
8 / Standard string_runtime_switch 2,709 → 2,621 1232 → 1232 2.92 → 2.94 0 → 0

jogibear9988 and others added 2 commits November 9, 2026 09:31
Fall back to ordered comparisons for numeric case tests that are evaluated at runtime. Stop constant-switch folding at a runtime-dependent test so its effects and first-match semantics are preserved.
@dadhi
dadhi merged commit 41268a8 into dadhi:master Nov 9, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/runtime-switch-tests-standalone branch November 9, 2026 22:19
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