Consider constructor hot paths#724
Open
hadley wants to merge 4 commits into
Open
Conversation
Move class_type() into C so callers avoid a chain of R-level inherits() calls. Read the class attribute once, walk it once, and compare interned CHARSXP pointers while retaining the previous type-priority order for pathological multi-tagged objects. Preserve and reuse the returned type strings to avoid allocation. Keep a NULL fast path in class_properties() because S7_object is bootstrapped before the DLL is registered; this keeps devtools::load_all() working in a fresh interactive session. Median class_type() time drops from 615-3,731 ns depending on the class representation to 205-246 ns. Depth-5 and depth-10 construction benchmark at 213 us and 420 us, respectively. Tests: R_TESTTHAT_QUICK=true Rscript -e 'devtools::test()' (1,200 passed, 3 expected skips).
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.
_S7_dispatchattributeclass_type()in C since it's called a lot, and means we can ensure that the first and last types get the same performance (old: 600-3000ns, new 200-250ns)Part of #723
This gives a meaningful performance to construction:
Depth 0 is one class directly extending
S7_object; depths 5 and 10 add that many parent links.Also helps with
S7_inherits()andsuper():S7_inherits()andsuper()were benchmarked using an instance of the deepest class and the root user class as the target.S7_inherits()super()