AngouriMath

Navigation

← Back to list of members

Sort​(AngouriMath.​Functions.​TreeAnalyzer.​SortLevel)

 Method (no overloads)

Summary

SortRules(AngouriMath.Functions.TreeAnalyzer.SortLevel), as data — one set per sort level.

Remarks

The first set here that is parameterised by something other than the expression. A switch takes that as a second argument and closes over it; a set of rules
closes over it too, but the set itself then has to be built per value rather than
declared once.
And it is not wired, because the exchange is not free here — measured, and
re-measured.
The three canonical orders are the normalisation: they run on
every node of every simplification pass, where every other set fires on a shape.
The figure first recorded here was +48% of SimplifyEasy, which the
kernel gate reported as 4.14x on a shared runner. That number has since stopped
being true
, and it was only ever a statement about the matcher of the day: with
bounded matching (#1079)
and rules indexed by node type (#1085) the same wiring measures +13.3% —
97,048 ns to 109,968 ns on the repository's own benchmark, with allocation +0.28% and
inside the gate's band. The decision is unchanged and the reason for it is a third of
what it was.
What is left is not dispatch across the rules. Every rule here is typed —
Any<Sumf>, Any<Mulf> — so the index tries one or two of them
at a node, not seven. It is the layer itself: a rule is a match that binds a name and
a delegate that reads it back, where a switch arm is a type test and a call.
Everywhere else that layer buys something — a pattern that says what the rewrite is,
reversible, addressable. Here every rule is a type test and a call already, so
there is nothing for it to buy. That is the boundary, and it is about what a rule
is rather than about where it runs.
Giving each rule a concrete root type instead of a predicate over
Any<Entity> was tried when the figure was 48%, on the reading that a hole
typed Entity matches every node before its predicate is consulted. It moved
+52% to +48%, so that was not the cost either.
So this stays here, proven to agree with the switch at every level, and the
switch keeps running. It is the one set where the answer to "should this be
data?" is no, and the reason is a number rather than a preference — a number that has
to be re-measured when the matcher changes, since it already has been once.
Every rule is a bare type test with the whole node bound, which is a typed hole — and
two of the seven test two types, a sum being either Sumf or
Minusf and a product either Mulf or Divf, which is the predicate
on a hole again. All seven replacements are code: sorting a chain is not a tree
written down.

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4378 pages online