Skip to content

perf: reduce per-figure Bokeh model overhead in .json.gz files#29

Merged
wdconinc merged 1 commit intomainfrom
copilot/glyph-optimization
Mar 12, 2026
Merged

perf: reduce per-figure Bokeh model overhead in .json.gz files#29
wdconinc merged 1 commit intomainfrom
copilot/glyph-optimization

Conversation

@wdconinc
Copy link
Contributor

Briefly, what does this PR introduce?

Two independent optimizations that together cut each per-collection .json.gz file by ~21% on top of the options-list fix:

  1. Remove BoxZoomTool per figure (tools='pan,wheel_zoom,reset,save) Each figure previously received the default Bokeh toolbar, which includes a BoxZoomTool together with a BoxAnnotation, BoxInteractionHandles, and AreaVisuals. These are serialized once per figure (~1,800 bytes each). With gridplot merge_tools=True those objects are replicated for every histogram in the collection. Wheel zoom covers the same use-case for 1D histograms.

  2. Share nonselection_glyph with glyph on each renderer Bokeh auto-creates a separate nonselection_glyph for every GlyphRenderer (the dim version shown when another element is selected). Since no selection tools are present in the toolbar, this state is never reached. Setting renderer.nonselection_glyph = renderer.glyph makes both attributes reference the same object; Bokeh then serializes it once and emits a short id-reference (~30 bytes) for the second occurrence instead of a full duplicate (~280 bytes on average).

What kind of change does this PR introduce?

  • Bug fix (issue: output json largely redundant)
  • New feature (issue #__)
  • Documentation update
  • Other: __

Please check if this PR fulfills the following:

  • Tests for the changes have been added
  • Documentation has been added / updated
  • Changes have been communicated to collaborators

Does this PR introduce breaking changes? What changes might users need to make to their code?

No.

Does this PR change default behavior?

No.

Two independent optimizations that together cut each per-collection
.json.gz file by ~21% on top of the options-list fix:

1. Remove BoxZoomTool per figure (tools='pan,wheel_zoom,reset,save')
   Each figure previously received the default Bokeh toolbar, which
   includes a BoxZoomTool together with a BoxAnnotation,
   BoxInteractionHandles, and AreaVisuals. These are serialized once per
   figure (~1,800 bytes each). With gridplot merge_tools=True those
   objects are replicated for every histogram in the collection. Wheel
   zoom covers the same use-case for 1D histograms.

2. Share nonselection_glyph with glyph on each renderer
   Bokeh auto-creates a separate nonselection_glyph for every
   GlyphRenderer (the dim version shown when another element is
   selected). Since no selection tools are present in the toolbar, this
   state is never reached. Setting renderer.nonselection_glyph =
   renderer.glyph makes both attributes reference the same object;
   Bokeh then serializes it once and emits a short id-reference (~30
   bytes) for the second occurrence instead of a full duplicate (~280
   bytes on average).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 12, 2026 01:46
@wdconinc
Copy link
Contributor Author

After #28 this is not quite as impactful. The capybara-reports directory goes down from 6608 to 6432 kB.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Member

@veprbl veprbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wdconinc wdconinc merged commit 7953fff into main Mar 12, 2026
5 of 6 checks passed
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.

3 participants