Repository navigation
Performance issues, verified against the code: slice release, std.math inline, skynet runs (#3853, #3852, #3868) - #3871
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
aether_slice_unref's counted path (string release, a published count, the last reference's free) moves into a cold helper, marked likeAETHER_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.std.mathscalar functions inline (c0c4783). These are sqrt, abs, min, max, clamp, floor, ceil, round and their f32 forms, fromaether_math_inline.hthrough@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 exportedmath_*functions are the same bodies.BENCH_SKYNET_RUNS, never fewer thanBENCH_RUNS) for all 11 languages at once, and recorded inruns_per_benchmark.Verified, tried, and left out (evidence on each issue)
sender_idis not tracing-onlyfanin_8_actors+12%; reverted-falign-*mean −0.4% over 68 rows, archive +8.7%; not merged--emit=effectsdoesn't cover handlers; signals only underAETHER_CATCH_SIGNALS=1)@inline@uniqType of Change
Testing
tests/regression/test_math_inline_scalars.aepins 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 testpasses.make ci-cooppasses.make test-ae: 2326 passed. The failures are the 8 TLS/IPv6 tests that also fail on untouched main on this machine, pluscodegen_no_silent_caps, which fails under full-suite load and passes standalone (2/2).ae fmt --check std examples tests) andcheck-changelogpass.-O2 -Wall -Wextra -Werrorbuildsaether_math.candaether_string.c(a slice user). The math header compiles alone under GCC and clang-std=c11 -Werror; clang emitsfsqrtandfrintmfor it.-lmis already linked), no module declaring thesemath_*externs itself, theexportsand--emit=libconsumers, and the runner'spcfg. It found thef32_arithmeticgrep, now fixed.Precision note: on x86-64 MinGW,
math.sqrtis nowsqrtsd, 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
Apple M5 Pro, against main 128f58b:
slice_view_returned(2 rounds)slice_view_bound(2 rounds)listheaprechecked 3×: -4.7, -2.9, +7.0)Checklist
🤖 Generated with Claude Code