Reduce direct RTTI to a single reflection - #81
Open
mingxwa wants to merge 1 commit into
Open
Conversation
direct_rtti added three conventions to carry proxy_cast, so every proxiable pointer paid three function pointers of metadata and every cast went through one of them. The typeid reflection that the same skill installs already records the contained type, and once that type is known to match the requested one the cast is a static_cast on the pointer storage, so the indirection buys nothing. direct_rtti now adds one reflection. direct_rtti_reflector inherits proxy_typeid_reflector for the type identity and reuses the accessor generated for proxy_cast_dispatch, so the five proxy_cast overloads and their qualifier mapping stay in one place. proxy_cast_accessor_impl gained a private invoke_cast that tests the reflected type and then invokes the same dispatch through an erased context with the contained type known statically. The indirect path keeps its conventions and compiles to the same code as before. The metadata of a facade built from direct_rtti alone drops from 40 bytes to 16, and the lvalue, pointer and rvalue casts compile to 27, 29 and 34 instructions in place of 46, 37 and 66. No indirect call is left on the success path. The rvalue form keeps one on the type mismatch branch, where the proxy is reset through the erased destructor.
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.
skills::direct_rttiinstalled three conventions to carryproxy_cast, so every proxiable pointer paid three function pointers of metadata and every cast went through one of them. The typeid reflection that the same skill already installs records the contained type, and once that type is known to match the requested one the cast is astatic_caston the pointer storage, so the indirection buys nothing.Changes
skills::direct_rttito a single reflection, because the reflection it already installed is enough to identify the contained type.direct_rtti_reflector, which inheritsproxy_typeid_reflectorfor the type identity and reuses the accessor generated forproxy_cast_dispatch, so the fiveproxy_castoverloads and their qualifier mapping stay in one place.invoke_casttoproxy_cast_accessor_impl, which tests the reflected type and then invokes the same dispatch through an erased context with the contained type known statically. The indirect path is unchanged and compiles to the same code as before.Effect
Metadata for a facade built from
direct_rttialone drops from 40 bytes to 16. Measured onfeature/v5with g++-16 at-O2on aarch64.The indirect call remaining in the rvalue form sits on the type mismatch branch, where the proxy is reset through the erased destructor. The success path has none.
The existing RTTI tests pass unchanged, so no test was added or modified.