Share one safeSelf() cache between the scriptlets in a frame - #63
Merged
Merged
Conversation
philipp-classen
force-pushed
the
avoid_exponential_call_explosion
branch
from
October 2, 2026 11:05
d7df476 to
ba330c4
Compare
smalluban
reviewed
Oct 2, 2026
Contributor
|
The args are serialized and copied, so we cannot use |
Context: Each scriptlet has its own copy of safeSelf(). It saves the functions that it finds when it first runs, and those were often already the wrappers that earlier scriptlets had installed, not the browser's own functions. So each hook called all earlier hooks again. With six hooks on JSON.stringify (as on youtube.com), one JSON.stringify call from the page became 2^6=64 native calls. The extension gives each scriptlet its own copy of scriptletGlobals, so the first scriptlet in a frame (and world) now keeps the cache on globalThis, and the later scriptlets use it. The property is read-only, and its key has the uBO version, so other versions do not share it. This works for all injection paths (registered scripts and executeScript), without changes in the extension. refs ghostery/ghostery-extension#3672
philipp-classen
force-pushed
the
avoid_exponential_call_explosion
branch
from
October 2, 2026 11:30
ba330c4 to
1e2de50
Compare
smalluban
approved these changes
Oct 2, 2026
This was referenced Oct 5, 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.
Context: Each scriptlet has its own copy of safeSelf(). It saves the functions that it finds when it first runs, and those were often already the wrappers that earlier scriptlets had installed, not the browser's own functions. So each hook called all earlier hooks again. With six hooks on JSON.stringify (as on youtube.com), one JSON.stringify call from the page became 2^6=64 native calls.
The extension gives each scriptlet its own copy of scriptletGlobals, so the first scriptlet in a frame (and world) now keeps the cache on globalThis, and the later scriptlets use it. The property is read-only, and its key has the uBO version, so other versions do not share it. This works for all injection paths (registered scripts and executeScript), without changes in the extension.
refs ghostery/ghostery-extension#3672