Skip to content

perf(viewer): reuse click handlers instead of rebuilding them per render - #556

Open
omkargaikwad23 wants to merge 1 commit into
perf/shared-trends-cachesfrom
perf/handler-identity-cache
Open

perf(viewer): reuse click handlers instead of rebuilding them per render#556
omkargaikwad23 wants to merge 1 commit into
perf/shared-trends-cachesfrom
perf/handler-identity-cache

Conversation

@omkargaikwad23

Copy link
Copy Markdown
Collaborator

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 CLIGive Feedback 💬

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
omkargaikwad23 force-pushed the perf/handler-identity-cache branch from 56fc2fd to e1936fb Compare August 20, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant