| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Use separate bytearray buffers for message ids and translations instead of rebuilding bytes objects for each entry. Keep the same offsets and final bytes write. Add tests for encodings, contexts, plural forms, fuzzy entries and writing the output once.
| Back | FazBrowse Home | New Git URL |
write_mo builds two byte strings as it adds each message. Each append copies the content already in that string, so larger catalogs spend more time copying earlier messages.
This changes those two buffers to separate bytearrays. The rest of the function stays the same: it filters and sorts the same messages, calculates the same offsets, and makes one write with a bytes object.
For similarly sized messages, building the string tables goes from quadratic copying to linear work. Sorting is unchanged. This does not remove all allocation costs, and peak memory is slightly higher in the measured cases.
Tests
Benchmarks
I measured the complete write_mo call on Python 3.15.0 and Windows 11, using the median of eight timing runs and eight separate peak-allocation runs per version. The base was e2a1791.
Catalog construction, PO parsing, downloads and output checks were outside the timer. Each call wrote to a fresh BytesIO. One process was limited to two physical cores at a time; core pairs rotated between repeats, paired versions used the same pair, and their order alternated. Memory below is newly traced Python allocations during the write, not total process RAM.
There are 100 generated catalog examples, two empty-catalog controls, and six cases using unchanged Django and Wagtail catalogs. The real-project cases measured 1.09×–1.48× faster. Tiny cases sometimes measured slower, and small differences can be noise. All 108 cases, including slower results and memory increases, are included below.
The runner, CPU helper, raw samples and rerun instructions are on a separate branch in my fork, so they do not add files to this PR.
Show all 108 measured casesPublic fixture sources: