Skip to content

perf(plot): buffer commands in \pgfplothandlerrecord - #1486

Open
diracdeltafunk wants to merge 1 commit into
pgf-tikz:masterfrom
diracdeltafunk:perf/plot-record-buffer
Open

diracdeltafunk wants to merge 1 commit into
pgf-tikz:masterfrom
diracdeltafunk:perf/plot-record-buffer

Conversation

@diracdeltafunk

Copy link
Copy Markdown
Contributor

This code was written by Claude Opus 5.5, and reviewed/edited by myself and Hood Chatham.

Motivation for this change

\pgfplothandlerrecord appended every plot stream command to the recording macro with \gdef, copying the whole recording each time. Since TikZ records every plot coordinates stream, such plots take quadratic time in the number of points. Collect commands in a small buffer instead and append it to the recording every 64 commands and at the end of the stream. The recorded macro is the same, and the time complexity is still quadratic, but now the constant has been cut by a factor of roughly 64.

Checklist

Please signoff your commits to explicitly state your agreement to the Developer Certificate of Origin. If that is not possible you may check the boxes below instead:

\pgfplothandlerrecord appended every plot stream command to the
recording macro with \gdef, copying the whole recording each time.
Since TikZ records every `plot coordinates` stream, such plots took
quadratic time in the number of points (16000 points: 16.3 s).

Collect commands in a small buffer instead and append it to the
recording every 64 commands and at the end of the stream. The recorded
macro is token for token the same (16000 points: 1.5 s, identical
PDF). The time complexity is still quadratic, but now the constant
has been cut by a factor of roughly 64.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Spitz <1844060+diracdeltafunk@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant