Skip to content

perf(core): a quantity spec operation computes its sign only where it can need a tag - #930

Merged
mpusz merged 5 commits into
masterfrom
perf/lazy-sign
Dec 5, 2026
Merged

mpusz merged 5 commits into
masterfrom
perf/lazy-sign

Conversation

@mpusz

@mpusz mpusz commented Dec 4, 2026

Copy link
Copy Markdown
Owner

#926 made every *, /, pow, and inverse of quantity specifications compute the sign of both operands and of the result, which raised the compile-time gate (accepted in the re-record at f2d8a91). This PR computes the sign only where the result can need a tag:

  • * and / skip it when the result kept every factor of both operands. Only a factor that cancels (I / I, length / length) can make the sign of the factors differ from what the operation says.
  • pow skips it for an odd power, and inverse always, for operands without a tag or a kind.
  • An untagged derived specification defines its members itself instead of inheriting derived_quantity_spec_core, which saves a class instantiation per specification.
  • has_sign_flag() gives way to the is_sign_tagged variable.

The result types don't change.

Measurements

Measured with clang 23 and libc++, C++23, on the use basis:

scaling/specs_broad_256 master this PR before #926
instantiations 7,530 6,304 5,940
function declarations 3,710 2,905 2,655
constraint checks 84,102 76,295 69,713

The specs_broad slope falls from 29.2 to 24.5 instantiations and from 14.4 to 11.3 declarations per step, typed_broad from 127.8 to 123.7 instantiations. The local gate against the current baselines reports 40 rows improved past the band. The baselines will be re-recorded after the merge.

Testing

The 134 tests and the header-set check pass with GCC 15 in C++26, and the 131 tests with GCC 12 and Clang 16 in C++20. With MSVC in C++20 and /W4 /WX, the sign-related static tests compile without a warning. The pre-commit hooks pass.

🤖 Generated with Claude Code

mpusz and others added 5 commits December 4, 2026 16:35
… can need a tag

#926 made every `*`, `/`, `pow`, and `inverse` of quantity specifications compute the
sign of both operands and of the result. For operands without a sign tag or a kind, the
result can need a tag only where a factor cancels (`I / I`, `length / length`) or for an
even power of a signed base. The operators now skip the sign when the result kept every
factor of both operands, for an odd power, and for an inverse. An untagged derived
specification also defines its members itself instead of inheriting
`derived_quantity_spec_core`, which saves a class instantiation per specification, and
`has_sign_flag()` gives way to the `is_sign_tagged` variable. The result types don't
change.

Measured with clang 23 and libc++, C++23, on the use basis against master 294e85d,
with the value before #926 in parentheses: `scaling/specs_broad_256` takes 6,304
instantiations instead of 7,530 (5,940), 2,905 function declarations instead of 3,710
(2,655), and 76,295 constraint checks instead of 84,102 (69,713). The `specs_broad`
slope falls from 29.2 to 24.5 instantiations and from 14.4 to 11.3 declarations per
step, `typed_broad` from 127.8 to 123.7 instantiations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is suppressed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mpusz
mpusz merged commit f8ce1f2 into master Dec 5, 2026
107 checks passed
@mpusz
mpusz deleted the perf/lazy-sign branch December 5, 2026 07:47
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