Skip to content

Label collision solve in a worker #23

Description

@barrulus

The collision pass is main-thread-bound only because it measures labels with getBoundingClientRect - thousands of forced reflows at every gesture end on a big map. Text metrics do not need the DOM: OffscreenCanvas measureText in a worker returns the same advance widths for the same font string.

Main thread sends label text, font, letter spacing, anchor position and rank. The worker runs the existing selectNonOverlapping and obstacle logic (already pure) and posts back the keep set of ids. Main thread toggles hidden classes in one write pass. Stamp requests with a generation counter and drop stale replies.

Risk: metric drift vs rendered SVG text. Port the existing letter-spacing and shadow fudge factors. Verify same keep sets on the same seed, then wall clock at settle.

Recommended first: smallest surface, biggest settle-time win.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions