Repository navigation
Perf/test time - #148
Merged
Merged
Perf/test time#148
Conversation
Writing a BYML took 17 times longer than reading it. The writer found repeated containers by serializing every subtree once per ancestor, and sorted map keys by building a new folded key on every comparison. Containers now get a shape id once, bottom up, and the sort compares the folded keys without allocating. Strings are borrowed instead of cloned. ActorInfo writes in 77 ms instead of 308 ms. Every BYML in the game (148,727 of them) writes back the same as with the old writer, and five preset seeds build byte for byte the same mods. A default seed builds in 20 s instead of 33 s and Full Shuffle in 50 s instead of 78 s.
The core and cosmetics test binaries use mimalloc. The system allocator on Windows slows down when many tests allocate at once: 24 of the heaviest tests took 278 s with it and 176 s with mimalloc. It is a dev-dependency behind cfg(test), so the shipped builds do not change. The sfx bank test builds its two seeds on two threads.
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.
Faster test suite (and faster mod builds)
The full test run with the game tests on had grown to about 12 minutes, around 20 minutes with the compile. This PR roughly halves the test run. I'd like your thoughts before it goes in, especially on the two questions at the end.
Numbers
Measured with
cargo test --workspace --profile ci,OOTRR_ROMFSset, on a 6-core Windows machine.Slowest tests, seconds inside the full run:
seed_packs::key_items_at_every_spot_class_...frost::a_seed_with_them_buildsdoor_open::every_build_carries_the_pedestal_fix_...fire_gorons::the_boss_key_chest_is_unlocked_in_full_buildsWhat was slow
About 100 of the 2400 tests take 85% of the time. Nearly all of them build a whole mod. Two things made each build slow.
1. The BYML writer. Writing a BYML took 17 times longer than reading it (ActorInfo: 308 ms to write, 18 ms to read). Every pickup pack in a seed rewrites the three actor tables, one pack after another, so a wide seed spent most of its build time in the writer. Two parts of
byml.rsdid most of it:Strings are also borrowed instead of cloned. ActorInfo now writes in 77 ms.
2. The Windows system allocator. With 12 tests building at once, the heavy tests ran about 3 times slower than alone. The core and cosmetics test binaries now use
mimalloc. On 24 of the heaviest tests that took the run from 278 s to 176 s. It is a dev-dependency behindcfg(test), so the shipped builds and the wasm build do not change.The sfx bank test also builds its two seeds on two threads now instead of one after the other.
What this changes outside the tests
Seed generation (placement, logic, the seed file) is untouched.
The BYML writer is used when a mod is built, so that part does run for players. It produces the same bytes, which I checked two ways:
Because of the writer change, builds are faster for players too: a default seed takes 20 s instead of 33 s, and Full Shuffle 50 s instead of 78 s.
Checklist
Questions for reviewers
mimalloc, withlibmimalloc-sysandcc) OK? Without it the suite still gets about 25% faster from the writer alone.ootrrbinary usemimalloctoo? A single seed build went from 48 s to 30 s with it. I left it out because it changes the release build.Happy to split the writer change and the test changes into separate PRs if that is easier to review.