Skip to content

Performance issues, verified against the code: slice release, std.math inline, skynet runs (#3853, #3852, #3868) - #3871

Merged
nicolas-maman merged 3 commits into
mainfrom
perf/verified-issues
Nov 24, 2026
Merged

nicolas-maman merged 3 commits into
mainfrom
perf/verified-issues

Conversation

@nicolas-maman

Copy link
Copy Markdown
Collaborator

Description

The open performance issues, checked against the code before any change was made. Four independent read-only verifiers each had to quote file:line for every verdict. This PR contains the changes that held up and measured a gain. Everything else is recorded on its issue with the evidence.

Closes #3853, closes #3852, closes #3868.

In this PR (one commit each)

  1. Slice release: an inline flag check for a view, the counted path out of line #3853: a slice release is inline for a view (9c183f8). aether_slice_unref's counted path (string release, a published count, the last reference's free) moves into a cold helper, marked like AETHER_SLICE_FAIL. The uncounted test and the common counted case stay inline: an unpublished buffer's reference that isn't the last. Each flag and count combination gives the same result as before.
  2. std.math: scalar functions (sqrt first) inline, sqrt as one instruction, #3027 rounding kept #3852: std.math scalar functions inline (c0c4783). These are sqrt, abs, min, max, clamp, floor, ceil, round and their f32 forms, from aether_math_inline.h through @c_include / @extern(...) @c_import, the Performance: string.length and string.char_at are out-of-line calls; inline them (3x on a scan) #3836 pattern. GCC and clang use the builtins, so no <math.h> enters generated C, where a program may define libm-named functions. Other compilers get <math.h>, which generated C already includes for them. The exported math_* functions are the same bodies.
  3. Cross-language skynet runs ~0.3 ms: too short to rank (cv 14-27%) #3868: skynet's median over 25 runs (d006951). Set in the runner (BENCH_SKYNET_RUNS, never fewer than BENCH_RUNS) for all 11 languages at once, and recorded in runs_per_benchmark.

Verified, tried, and left out (evidence on each issue)

Issue Verdict Outcome
#3867 delivery copies real; the issue undercounted (5–6 copies, not 4–5); sender_id is not tracing-only gather enqueue for mixed batches measured no gain (fork_join 41.2 → 42.1, noise); not merged
#3771 finding 10, cached queue indices real pattern measured no gain, and fanin_8_actors +12%; reverted
#3854 code placement real (rows move ±5–9% with identical code) global -falign-* mean −0.4% over 68 rows, archive +8.7%; not merged
#3866 frameless steps its premises were overstated (--emit=effects doesn't cover handlers; signals only under AETHER_CATCH_SIGNALS=1) corrected on the issue; needs design
#3844 shortest float digits real out of scope: 400–1,500 vendored lines, byte-identical JSON, 128-bit portability
#3849 @inline real new syntax, needs a maintainer decision
#1071 bounds-check elision partly real (constants already elided) memory-safety design
#1065 @uniq mostly stale (unaliased bindings already take no retain) design
#422 lookup hashing false for Aether (no runtime environment; the typechecker hashes since #2007) none

Type of Change

  • Performance improvement
  • Benchmark methodology (skynet runs)

Testing

  • New tests/regression/test_math_inline_scalars.ae pins fmin/fmax NaN handling (either side), abs_int(INT_MIN), half-away rounding, floor and ceil of negatives, and the f32 forms. It passes on main and on this branch, so the values are identical.
  • f32_arithmetic's codegen check now names the inline call (aether_math_sqrt_f32_inline). It still checks that the result is a float local.
  • make test passes. make ci-coop passes. make test-ae: 2326 passed. The failures are the 8 TLS/IPv6 tests that also fail on untouched main on this machine, plus codegen_no_silent_caps, which fails under full-suite load and passes standalone (2/2).
  • The format gate (ae fmt --check std examples tests) and check-changelog pass.
  • GCC 16 -O2 -Wall -Wextra -Werror builds aether_math.c and aether_string.c (a slice user). The math header compiles alone under GCC and clang -std=c11 -Werror; clang emits fsqrt and frintm for it.
  • Independent review: slice equivalence for every flag and count, builtin availability (GCC 4+, all clang, wasm, MinGW, xtensa/ARM GCC; -lm is already linked), no module declaring these math_* externs itself, the exports and --emit=lib consumers, and the runner's pcfg. It found the f32_arithmetic grep, now fixed.

Precision note: on x86-64 MinGW, math.sqrt is now sqrtsd, correctly rounded, where the CRT's x87 sqrt rounded twice (#3027). A result there may differ from before by one ulp, toward the correct value.

Performance Impact

  • Performance improvement

Apple M5 Pro, against main 128f58b:

main this PR
slice_view_returned (2 rounds) 0.86 ns 0.22 ns -74.7%
slice_view_bound (2 rounds) 3.35 / 3.34 ns 3.16 / 3.14 ns -6%
sqrt + floor + min + abs loop (5 interleaved runs) 2.38 ns/iter 1.98 ns/iter -17%
send, ask, pingpong, fanin rows within noise (2 rounds of 9)
ownership rows within noise (listheap rechecked 3×: -4.7, -2.9, +7.0)

Checklist

  • Code follows style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated (changelog fragments; cross-language README and config)

🤖 Generated with Claude Code

nicolas-maman and others added 3 commits November 24, 2026 16:31
…f line (#3853)

aether_slice_release is inlined at every place a slice dies, but
aether_slice_unref carried string_release, the buffer free and its element
drops, so compilers left the release out of line: a call per place for a
view, whose release is one test of its marks. The counted path that frees
or touches a published count moves to aether_slice_unref_counted, marked as
AETHER_SLICE_FAIL's helpers are (cold on GCC/clang, noinline on cl.exe);
the uncounted test and the common counted case (an unpublished buffer's
reference that is not the last, a view of a counted buffer stored again in
a loop) stay inline. The same result for every flag and count.

bench-core on an Apple M5 Pro against main 128f58b, two rounds:
slice_view_returned 0.86 -> 0.22 ns (-74.7%), slice_view_bound 3.34 -> 3.15
(-6%); ownership rows within noise (listheap rechecked: -4.7, -2.9, +7.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
math.sqrt, abs, min, max, clamp, floor, ceil, round and the f32 forms were
calls into libaether.a that each called libm. They now come from
aether_math_inline.h via @c_include and @extern(...) @c_import, as
std.string's reads do (#3836). On GCC and clang the header uses the
compiler's builtins and does not include <math.h> (generated C does not
include it there, and a program may define its own libm-named function);
other compilers get <math.h>, which generated C already includes for them.
The exported math_* functions are the same bodies.

Values are unchanged (test_math_inline_scalars passes on main and here:
fmin/fmax NaN handling, abs_int(INT_MIN), half-away rounding, f32), except
on x86-64 MinGW, where sqrt is now sqrtsd, correctly rounded, instead of
the CRT's double-rounding x87 sqrt (#3027). f32_arithmetic's codegen check
names the inline call.

A loop of sqrt, floor, min and abs: 2.38 -> 1.98 ns/iter on an Apple M5
Pro; clang emits fsqrt and frintm for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One skynet run creates 1,111 units in about 0.3 ms, so five runs left its
median to scheduling jitter (cv 14-27%). The runner times skynet
BENCH_SKYNET_RUNS times (default 25, never fewer than BENCH_RUNS) for every
language, through a per-pattern Settings, and records the count in
runs_per_benchmark. Documented in README.md and config.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicolas-maman
nicolas-maman merged commit 8eb8bc9 into main Nov 24, 2026
55 checks passed
@nicolas-maman
nicolas-maman deleted the perf/verified-issues branch November 24, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request runtime stdlib

Projects

None yet

1 participant