This trims two small pieces of repeated work from formatting hot paths:
use the already-compiled thousands-separator regex directly via .match(...) instead of routing every check through re.match(...)
skip _flat_list(...) when aligning single-line columns, where measured widths are already a flat list of integers
Both changes preserve the existing behavior and keep the multiline path unchanged.
Why
For larger tables, type inference calls _isnumber_with_thousands_separator() for many cells, and column alignment runs once per rendered column. Avoiding per-cell regex dispatch overhead and unnecessary single-line width flattening reduces work in the common table-rendering path.
Benchmark
Measured on Windows / Python 3.12 by loading upstream/master and this branch in the same process with timeit.repeat:
thousands-separator numeric detection, 19,999 values x 100: best 2.429s -> 1.310s (~46% faster)
single-line _align_column, 5,000 cells x 200: best 0.276s -> 0.240s (~13% faster)
tabulate(..., tablefmt="plain"), 5,000 rows x 10: best 1.249s -> 1.124s (~10% faster)
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
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.
What changed
This trims two small pieces of repeated work from formatting hot paths:
Both changes preserve the existing behavior and keep the multiline path unchanged.
Why
For larger tables, type inference calls _isnumber_with_thousands_separator() for many cells, and column alignment runs once per rendered column. Avoiding per-cell regex dispatch overhead and unnecessary single-line width flattening reduces work in the common table-rendering path.
Benchmark
Measured on Windows / Python 3.12 by loading upstream/master and this branch in the same process with timeit.repeat:
Validation