Skip to content

sitetile: paragraph soft-join in bodyHtml is quadratic on long paragraphs #30

Description

@cverorg

Found during PR #28's round-4 review, independent of that PR (reproduces on main).

bodyHtml()'s paragraph soft-join flattens the accumulated string on every line (joined.slice(-1) on a growing rope), so a single long paragraph — plain words, no comment syntax at all — renders in time quadratic in its size: about 540 ms for 512 KiB on main, and shapes like --> line\n repeated behave the same way.

Fix: accumulate lines in an array and join once per paragraph (or track only the last character separately). Add a linearity test in the ratio form used by site-core.test.js (256 KiB → 1 MiB ratio ≤ ~5×), not a fixed millisecond bound, since those are load-flaky.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions