Repository navigation
perf(core): a quantity spec operation computes its sign only where it can need a tag - #930
Merged
Merged
Conversation
… 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>
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.
#926 made every
*,/,pow, andinverseof 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.powskips it for an odd power, andinversealways, for operands without a tag or a kind.derived_quantity_spec_core, which saves a class instantiation per specification.has_sign_flag()gives way to theis_sign_taggedvariable.The result types don't change.
Measurements
Measured with clang 23 and libc++, C++23, on the use basis:
scaling/specs_broad_256The
specs_broadslope falls from 29.2 to 24.5 instantiations and from 14.4 to 11.3 declarations per step,typed_broadfrom 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