Profile tfl_table and add token-width memoization#37
Merged
Conversation
Profile harness (examples/profile_writetfl.R) identified .measure_text_width_in at wrap.R:160 as 73.7% of total time across the 18-demo wrap_demos sweep. Repeated tokens within paragraphs and across cells were paying the textGrob+grobWidth+convertWidth cost on every measurement. Add per-call width caches in .wrap_string() (threaded through .wrap_paragraph) and .column_min_token_width_in(), plus a unique() dedup in .measure_max_string_width(). Pattern mirrors the existing memo envs at R/table_rows.R:38 and R/wrap.R:713. Measured speedup (medians, 15 iterations): core_wrap 334 ms -> 225 ms (~33% faster) wrap_demos 9.88 s -> 3.43 s (~65% faster) core_small / core_paginate / figure_multi: within run-to-run noise Full devtools::test() green before and after. Documented as D-43 in design/DECISIONS.md. Profiling and benchmark scripts live under examples/ (already in .Rbuildignore). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Profile harness (examples/profile_writetfl.R) identified .measure_text_width_in at wrap.R:160 as 73.7% of total time across the 18-demo wrap_demos sweep. Repeated tokens within paragraphs and across cells were paying the textGrob+grobWidth+convertWidth cost on every measurement.
Add per-call width caches in .wrap_string() (threaded through .wrap_paragraph) and .column_min_token_width_in(), plus a unique() dedup in .measure_max_string_width(). Pattern mirrors the existing memo envs at R/table_rows.R:38 and R/wrap.R:713.
Measured speedup (medians, 15 iterations):
core_wrap 334 ms -> 225 ms (~33% faster)
wrap_demos 9.88 s -> 3.43 s (~65% faster)
core_small / core_paginate / figure_multi: within run-to-run noise
Full devtools::test() green before and after.
Documented as D-43 in design/DECISIONS.md. Profiling and benchmark scripts live under examples/ (already in .Rbuildignore).