Repository navigation
perf: keep generated values in the entity only (generate 1.2x faster) - #6
Merged
Merged
Conversation
Each component's value was copied into the generation context's map (a deep copy of the std::any, plus a wstring key) and also moved into the entity. The context now points at the entity's entry, whose storage is reserved up front so it never moves. Same draws, so output and signatures are unchanged. get<const T&>() already returned a reference into the stored value; it is now documented and tested, so a component can read a large dependency without copying it. Measured (clang 22, -O2): generate (3 components) 2.5 -> 2.1 us, a batch of 100 104 -> 65 us; persona-generator's get_persona 46 -> 40 us. All tests pass. 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.
Phase 3, step 6. Output and signatures are unchanged (a patch release, 4.0.1).
Each component's value was copied into the generation context (
std::map<std::wstring, std::any>: a deep copy of the value and a new key string) and also moved into the entity. The context now holds pointers to the entity's entry, key and value; the entries are reserved for every component before the loop, so they never move while the entity is generated. Lookup is a linear search over the values generated so far, asentity::getalready does.ctx.get<const T&>(key)already returned a reference into the stored value (it isstd::any_cast<const T&>). It is now documented, with a test, so a component can read a large dependency (a struct with strings and vectors) without copying it. persona-generator will use it next.-O2generate(3 components)generate_batchx100get_persona(8 components, lite)All tests pass (5,279 assertions), and persona-generator's known answers are unchanged with this header.
🤖 Generated with Claude Code