script: Use a u16 for prototype id to speed up Castable::is<T>()#44364
Merged
Conversation
Contributor
Author
|
Local testing shows the |
01c662e to
965e6c7
Compare
Signed-off-by: webbeef <me@webbeef.org>
0e846a0 to
dcf1b8e
Compare
Member
|
It kills me a little bit to take the memory hit for every reflected object, but the speed tradeoff is undeniable. |
jdm
approved these changes
Apr 25, 2026
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.
Castable::is<T>()callsget_dom_class()in a way that incurs a roundtrip to the JS engine andmultiple pointer indirections:
self.reflector().get_jsobject().get() -> JSObject
Object.shape -> BaseShape.clasp -> JSClass
DOMJSClass.dom_class -> DOMClass
interface_chain[depth] == ID -> bool
Since the ID doesn't change after creation of reflectors, we can instead store the ID on the reflector
and avoid most of that cost. The trick is to use a Depth First Search to generate IDs that allow a
range check for
Castable::is<T>. An example of IDs in the DFS looks like:EventTarget = 0
Node = 1
CharacterData = 2
Text = 3
CDATASection = 4
Comment = 5
ProcessingInstruction = 6
Document = 7
HTMLDocument = 8
XMLDocument = 9
Testing: Green try run at https://github.com/webbeef/servo/actions/runs/24640508040 and manual testing with general browsing.