Repository navigation
Small optimizations that improve search speed by 20% and reduce memory usage with no behavior differences. - #1008
Dragon-Hatcher wants to merge 15 commits into
Conversation
…plication SubstHelper::applyImpl and BottomUpEvaluation::apply took their stacks from Recycled on every call, which on small terms costs more than the work itself. Scratch keeps one object per nesting depth instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A subterm no heavier than the term being replaced (or a ground one, when it is a variable) cannot contain it, so it need not be traversed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CodeTreeTIS counts its keys by top symbol, so a query term whose top symbol has no key, while there are no variable keys, has no generalizations. Most forward demodulation queries are of this kind. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Term, literal and clause matchers are recycled between queries, but each query allocated new flat terms. They now keep the flat terms of the previous query and build the next ones in them, up to a size limit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The argument entries of an unexpanded function are uninitialized until it is expanded, and most of a fresh flat term is such entries, so copying (for the reversed and opposite literals of subsumption queries) skips them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The matcher calls expand() on every function entry it checks, and most are already expanded. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Literal matchers are entered and left many times in each subsumption query, so the clause matcher keeps one for each depth instead of taking them from Recycled each time. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When an operation fails, its alternative was pushed onto the backtracking stack only to be popped again immediately. Now the matcher moves to the alternative directly and pushes it only after a successful operation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Its default reset and keep policies are empty, so [[no_unique_address]] keeps them from taking space. Index query result iterators then fit the small object allocator. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Count variable occurrences in an array indexed by variable instead of a hash map, and walk subterms with an explicit stack instead of SubtermIterator. The hash values are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…trees The binding heap of an insertion is kept between calls, as unresolvedSplits already is, and the subterm stacks are recycled. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ast tried A term that had no applicable demodulator stays so until a demodulator whose left-hand side has the same top symbol, or is a variable, is inserted (removals cannot make one applicable). DemodulationLHSIndex records when such demodulators were last inserted, and terms record when they were last found irreducible, in what was padding in Term. Failures that depended on the clause (colours, the premise redundancy check) or on randomization are not recorded. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Inserting into or removing from the age and weight queues compared against the clause of every node passed, through a virtual call. Nodes now store the age and weight packed into one word, and the clause is only read on ties. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ary literal Matching reads a literal's polarity from the header entry only, so opposite literals of subsumption resolution queries and complementary literal code tree queries no longer look up or create the complementary literal. Not creating these literals changes the ids of literals made later, so where the search breaks ties by id it can differ on some problems. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Looking cool... I am curious to see how much each of these contributes! Can take care of giving it a thorough performance check :) |
|
Would appreciate a double check of my measurements. The changes are basically all 1-2% each. Just a lot of small improvements. |
|
It indeed looks really cool, thanks! I was also wondering how much each of these contribute.. we could decide on a case-by-case basis which ones are reasonable to merge without sacrificing code quality too much. |
|
Hello,
Great improvements, however testing on about 100 runs is not really
serious. Obviously, some changed do not even need to be tested (like fail
instead of push, fail, pop in code trees).
Hope to have Spider access to the cluster for proper testing ASAP.
Best, Andrei
…On Mon, 5 Oct 2026 at 10:00, Márton Hajdu ***@***.***> wrote:
*mezpusz* left a comment (vprover/vampire#1008)
<#1008 (comment)>
It indeed looks really cool, thanks! I was also wondering how much each of
these contribute.. we could decide on a case-by-case basis which ones are
reasonable to merge without sacrificing code quality too much.
—
Reply to this email directly, view it on GitHub
<#1008?email_source=notifications&email_token=ABVY4BOBTCWEBKVOAJXAV4T5SNPKBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGEZTEMJVG422M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5991321575>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABVY4BPD4OXA7IVS4AIMVJL5SNPKBAVCNFSNUABEKJSXA33TNF2G64TZHMYTQMBWG44TCMB3JFZXG5LFHM2TMOJVGQ3TAMRZHCQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ABVY4BMN3NU3S2VVMFMDNED5SNPKBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGEZTEMJVG422M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/ABVY4BMBLEUXDIFYYLJVRAD5SNPKBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGEZTEMJVG422M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
I do not have access to a lot of compute so it is hard for me to do large scale tests. Obviously bigger tests will be much more decisive about the true improvement. My hope is that most of these changes are simple enough that they are obvious wins even without testing. None are huge improvements on their own so if any individual one seems too messy to maintain, its fine to drop. |
|
As I mentioned, I noticed one which looked like an obvious glitch in the
code trees implementation - if the rest of them are similar obvious
optimizations, then we don't do extensive testing and yes, reported
improvements on 130 problems are sufficient to understand their value.
In any case, thank you for your work!
Best regards,
Andrei
…On Mon, 5 Oct 2026 at 10:53, Dragon-Hatcher ***@***.***> wrote:
*Dragon-Hatcher* left a comment (vprover/vampire#1008)
<#1008 (comment)>
I do not have access to a lot of compute so it is hard for me to do large
scale tests. Obviously bigger tests will be much more decisive about the
true improvement. My hope is that most of these changes are simple enough
that they are obvious wins even without testing. None are huge improvements
on their own so if any individual one seems to messy to maintain, its fine
to drop.
—
Reply to this email directly, view it on GitHub
<#1008?email_source=notifications&email_token=ABVY4BOP7FKOI3LOB7YG3QD5SNVQLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGIYTEMJWGQ42M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5992121649>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABVY4BNHQIDAAHEX47V63VT5SNVQLAVCNFSNUABEKJSXA33TNF2G64TZHMYTQMBWG44TCMB3JFZXG5LFHM2TMOJVGQ3TAMRZHCQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ABVY4BNEZCYDXQNEJNM43635SNVQLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGIYTEMJWGQ42M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/ABVY4BKXUG7GHF7RL6ZQR435SNVQLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJZGIYTEMJWGQ42M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you commented.Message ID:
***@***.***>
|
|
Here are my first results for a two short instruction-limited ( There are only two sequential diffs with no gain (or a tiny loss) in the number of problems solved and I will next have these tested uder a time limit (cache/memory related optimization sometimes only show up under wall clock). |
|
Overall, I think, we want to pick the really unproblematic ones immediately, but maybe not everything related to code trees, which are going to be an optimization target of the Vampire team in the near future anyway and abrupt changes there could complicate the work. If I do this by |
| hash = termFunctorHash(sub,hash); | ||
| toDo->push(ts->next()); | ||
| ts = sub->args(); | ||
| } |
There was a problem hiding this comment.
Is this basically inlining the SubtermIterator iteration?
Can this really be making a difference?
There was a problem hiding this comment.
By my benchmarks this and the other half of the commit contribute equally to the gain.
There was a problem hiding this comment.
OK, I see. It's not just inlining the SubtermIterator.
It's also using it as an opportunity to use Scratch.
However, I would argue using Scratch here is not well-justified. As we never call computeHashAndCountVariables(TermList*,...) recursively (it it will cost use 8 entries on the Scratch's stack). And SubtermIterator already uses a Recycled<Stack<const TermList*>>.
Shouldn't this be an opportunity to make SubtermIterator itself more efficient (better inline-able, perhaps, maybe moving hasNext() to the header), rather than bloating the iteration code here?
| if (counts[v]++ == 0) seen.push(v); | ||
| } | ||
| unsigned size() const { return seen.size(); } | ||
| }; |
There was a problem hiding this comment.
This other half seems reasonable if not major.
| BinaryHeap<Binding, BindingComparator<LeafData_>> remainingBindings; | ||
| for (auto [var, term] : iterTraits(svBindings.items())) { | ||
| remainingBindings.insert(Binding(var, term)); | ||
| static BinaryHeap<Binding, BindingComparator<LeafData_>> remainingBindings; |
There was a problem hiding this comment.
We are trying to get rid off the static as a design pattern.
Would it make sense to make it a member instead?
There was a problem hiding this comment.
Yes I measured and a member is fine.
| remainingBindings.insert(Binding(var, term)); | ||
| static BinaryHeap<Binding, BindingComparator<LeafData_>> remainingBindings; | ||
| remainingBindings.reset(); | ||
| typename BindingMap::Iterator bit(svBindings); |
There was a problem hiding this comment.
Also, iterTraits is the modern way and while (bit.hasNext()) slowly under removal.
Is the change of the loop essential for the improvement?
There was a problem hiding this comment.
I'll change it. Performance is the same without the while.
|
Under So I would drop I was expecting to see more benefit of |
|
Dropping the substitution tree change is fine with me. I wonder if the easiest way would be to open separate PRs for the changes we actually want to merge and treating this as a draft? I would have opened separate PRs for each change but I didn't want to open 15 separate PRs. |
|
|
||
| void swapCommutativePredicateArguments(); | ||
| /** Like changeLiteralPolarity(), but leaves the term entry pointing to the original literal. */ | ||
| void flipPolarity() |
There was a problem hiding this comment.
Could we simply rewrite changeLiteralPolarity instead of adding a new function?
A selected subset of improvements from #1008
|
So, I went ahead and merged: Could you, @Dragon-Hatcher , please pull the new master, rebase your In general, the code tree updates will be considered, but probably later as part of a larger effort. In "Speed up the variant index hash", I left a comment. I would love to save the |
A set of independent performance changes, mostly in code tree matching, flat terms, substitution application and forward demodulation. The only behavior difference comes from the polarity flipping change in the last commit which only effects term ids.
Results
Plain
-DCMAKE_BUILD_TYPE=Releasebuilds ofmaster(af03e15) and this branch,-sa discount -p off -t 30, on 72 TPTP problems from 23 domains used for benchmarking to find the optimizations and on 133 further problems sampled at random from TPTP as a holdout:No problem got slower by more than measurement noise.
Commits
(The commits are logical so it is probably easier to review them one at a time rather than looking at the whole diff).
Recycledfor working stacks needed on every call of small reentrant functions; used bySubstHelper::applyImplandBottomUpEvaluation::apply.EqHelper::replaceskips subterms that cannot contain the replaced term.CodeTreeTISanswers queries whose top symbol has no key (and there are no variable keys) without walking the tree.Entry::expand's already-expanded check is inline.ClauseMatcherkeeps one literal matcher per depth.Recycleduses[[no_unique_address]]for its policies, so it is the size of a pointer.Map::resetreturns early when empty.Termso doesn't increase the size ofTerm.