← 输入框|github.com|刷新
Skip to content

[profiler] Rasterize the node chips at 4x so they stay sharp in Safari - #7827

Merged
Karakatiza666 merged 2 commits into
mainfrom
profiler-sharp-chips-safari
Nov 8, 2026
Merged

Karakatiza666 merged 2 commits into
mainfrom
profiler-sharp-chips-safari

Conversation

@Karakatiza666

Copy link
Copy Markdown
Contributor

Fixes #7738

Cause

The node chips (</> and the operator count with the network icon) are SVG data: URIs that cytoscape draws with drawImage. WebKit rasterizes an SVG image at its intrinsic width/height before the draw. The chips had a 1x intrinsic size, so on a Retina screen Safari upscaled a 1x bitmap. Chrome re-renders the SVG at the target size, so it did not show the problem.

Fix

  • chips.ts: the SVG width/height are CHIP_RASTER_SCALE (4) times the viewBox. The viewBox and the cytoscape background-width/background-height do not change, so the layout and the chip hit boxes stay the same.
  • Why 4: cytoscape caches each node at a power-of-two scale (2^ceil(log2(zoom * devicePixelRatio)), max 4). On Retina at zoom above 1 that scale is 4, so a 3x image would still be upscaled.
Chip Drawing size Bitmap at 4x
Counter canvas 64.8 x 20 259 x 80
Code chip 29.6 x 16 118 x 64

Cytoscape decodes each distinct image URI once, and all nodes share it.

Tests

  • New test in chips.test.ts: the intrinsic size is at least 3x the viewBox (zoom 1.5 x devicePixelRatio 2), with the same aspect ratio. It fails without the fix.
  • Existing size checks read the viewBox instead of the SVG width/height.
  • Not checked live in Safari. A reviewer with a Mac should open a profile in Safari to confirm.
  • viewport.test.ts has 2 failures that also occur on main. This PR does not touch that file.

WebKit rasterizes an SVG image at its intrinsic size before cytoscape
draws it to the canvas. The chips had a 1x intrinsic size, so on a Retina
screen Safari upscaled a 1x bitmap and the icons looked blurry. Chrome
re-renders the SVG at the target size, so it did not show the problem.

The chip SVGs now have a 4x intrinsic size. The viewBox and the cytoscape
background size stay the same, so the layout does not change. Cytoscape
caches each node at a power-of-two scale of up to 4, so 4x matches its
largest cache scale.

Fixes #7738
it('rasterizes above the size it is drawn at, so Safari does not upscale a 1x bitmap', () => {
// WebKit rasterizes an SVG image at its intrinsic size. Cytoscape then scales that bitmap by
// zoom (up to 1.5) and devicePixelRatio (2 on Retina).
const MIN_SCALE = 1.5 * 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pitfall (medium): This floor (3) doesn't match the reasoning in chips.ts. There, cytoscape caches at power-of-two scales, so on Retina at zoom > 1 the scale is 4, and "a 3x image would still be upscaled" (from the PR description). If someone drops CHIP_RASTER_SCALE to 3, this test still passes and the blur comes back. Set the floor to the cache scale, e.g. 2 ** Math.ceil(Math.log2(1.5 * 2)) (= 4), so the test checks the stated invariant. Also, 1.5 duplicates maxZoom(1.5) from viewport.ts. Consider exporting that as a constant.

@mythical-fred-oss

Copy link
Copy Markdown
Contributor

What I ran (profiler-lib):

Check Result
bun run check (tsc) ✅
vitest chips + diagramTheme ✅ 47/47
New test with CHIP_RASTER_SCALE = 1 ❌ fails as expected, so it guards the fix
Full vitest 2 failures in viewport.test.ts (zoom 1 vs 11.25/12). The PR doesn't touch that file.
pre-commit on changed files ✅
  • missing (medium): Nobody has checked this in Safari yet. Gate 1 passes because unit tests cover the size change. But they can't show the blur is gone. Someone with a Mac should confirm on a Retina screen at zoom 1.5 before merge.
  • tech-debt (medium): The viewport.test.ts failures on main mean red CI doesn't mean anything right now. Please open a tracking issue.

Otherwise LGTM. The layout and hit boxes stay the same because viewBox/background-* didn't change. The commit message is good.

The test floor was zoom * devicePixelRatio (3), so a CHIP_RASTER_SCALE
of 3 passed although cytoscape caches nodes at scale 4 on Retina at
zoom above 1. The floor is now that power-of-two cache scale. The max
zoom is the MAX_ZOOM constant, shared by viewport.ts and the test.
@Karakatiza666
Karakatiza666 added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 8060701 Nov 8, 2026
1 check passed
@Karakatiza666
Karakatiza666 deleted the profiler-sharp-chips-safari branch November 8, 2026 02:20
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.

Icons in pipeline profiler look blurry in MacOS on Safari

2 participants