Perf: compute global features once per file; single hash lookup in Feature::evaluate - #19
Merged
Merged
Conversation
This was referenced Jul 27, 2026
…ate (closes marirs#18) - smda extractor: extract_global_features paid a full goblin parse of the buffer for the OS feature on every call — and it was called per instruction, per basic block and per function. OS/arch are constant per file, so the result is now cached in a once_cell::sync::OnceCell (thread-safe for the rayon per-function loop). Instruction-level extraction on mimikatz.exe_ (808 KiB, ~136k insns) drops ~8.4s -> ~0.2s (~40x); Demo64.dll ~23ms -> ~3.4ms. Extracted feature sets are unchanged. - rules/features: all 20 Feature::evaluate sites used contains_key + indexing, doing two hash lookups and cloning self (with its HashSet<Scope>) twice per hit in the hottest path of the engine. Now a single HashMap::get, matching RangeStatement's existing pattern.
mnaza
force-pushed
the
perf/global-features-cache
branch
from
July 31, 2026 08:57
c356be9 to
5b26ce4
Compare
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.
Closes #18.
1. Cache global features per extractor
extract_global_featurespaid a fullgoblin::Object::parse(self.buf())for the OS feature on every call — and it is called per instruction (extract_insn_features), per basic block and per function. OS/arch are constant per file, so the result is now computed once and cached in aonce_cell::sync::OnceCellon the smda extractor. Thesyncflavour is required becausefind_capabilitiesshares the extractor across rayon worker threads;get_or_try_initkeeps error propagation intact.Measured with a harness that runs
extract_insn_featuresover every instruction (release build, identical extracted feature sets before/after):data/mimikatz.exe_(808 KiB, ~136k insns)data/Demo64.dll(29 KiB, ~1k insns)The gain grows with file size (parse cost scales with the buffer), so large real-world binaries benefit the most.
2. Single hash lookup in
Feature::evaluateAll 20 feature types (
Api,Number,String,Os, …) used:— two hash-map lookups plus two clones of
self(including itsHashSet<Scope>heap allocation) on every hit, in the hottest operation of the rule engine ((rules × features) evaluations per function). All 20 sites now do a singlefeatures.get(...), the patternRangeStatementinsrc/rules/statement.rsalready used.Tests: 13/13 pass, clippy clean, fmt applied, CHANGELOG entry under
[Unreleased]. Independent of #17 (based on master); only the CHANGELOG[Unreleased]heading will trivially conflict with it.