perf(viewer): reuse click handlers instead of rebuilding them per render - #556
Open
omkargaikwad23 wants to merge 1 commit into
Open
perf(viewer): reuse click handlers instead of rebuilding them per render#556omkargaikwad23 wants to merge 1 commit into
omkargaikwad23 wants to merge 1 commit into
Conversation
omkargaikwad23
marked this pull request as ready for review
August 10, 2026 04:53
omkargaikwad23
requested review from
IsmailMehdi,
helloeve and
prernakakkar-google
as code owners
August 10, 2026 04:53
omkargaikwad23
force-pushed
the
perf/handler-identity-cache
branch
from
August 20, 2026 08:12
0828d08 to
56fc2fd
Compare
Six factories built a fresh closure for every dropdown option on every render and registered it in globals(). Mesop memoizes handler ids on the function object itself (compute_fn_id is an unbounded lru_cache), so a new closure per render meant a permanent entry per render: 300 renders of a 40-option dropdown added 12,000 entries instead of 40. Hoist the factories to module level and memoize them by value, so the same option yields the same function object and mesop's table stays flat. The globals() writes go with them; nothing ever read those names. Handler __name__ is load-bearing and stays: mesop derives identity from name plus source, and all handlers from one factory share source, so without it every option in a dropdown would dispatch to the same value. Names now carry a short digest of the raw value, since the old sanitizer mapped "a.b" and "a-b" to one name and silently merged them.
omkargaikwad23
force-pushed
the
perf/handler-identity-cache
branch
from
August 20, 2026 08:23
56fc2fd to
e1936fb
Compare
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.
Six factories built a fresh closure for every dropdown option on every
render and registered it in globals(). Mesop memoizes handler ids on the
function object itself (compute_fn_id is an unbounded lru_cache), so a new
closure per render meant a permanent entry per render: 300 renders of a
40-option dropdown added 12,000 entries instead of 40.
Hoist the factories to module level and memoize them by value, so the same
option yields the same function object and mesop's table stays flat. The
globals() writes go with them; nothing ever read those names.
Handler name is load-bearing and stays: mesop derives identity from
name plus source, and all handlers from one factory share source, so
without it every option in a dropdown would dispatch to the same value.
Names now carry a short digest of the raw value, since the old sanitizer
mapped "a.b" and "a-b" to one name and silently merged them.
Stack created with GitHub Stacks CLI • Give Feedback 💬