Skip to content

perf: share repeated server-list strings - #27

Open
UglyEgg wants to merge 1 commit into
ProtonVPN:stablefrom
UglyEgg:contrib/server-string-sharing
Open

UglyEgg wants to merge 1 commit into
ProtonVPN:stablefrom
UglyEgg:contrib/server-string-sharing

Conversation

@UglyEgg

@UglyEgg UglyEgg commented Sep 13, 2026

Copy link
Copy Markdown

Problem

Large server lists retain separate Python strings for repeated immutable country, location, endpoint, generation, and label values across logical and physical records.

Change

Share equal selected values within one server-list load. Fresh HTTP-decoded lists are normalized before model construction. Cached JSON uses the same policy while decoding, which also lowers peak allocation. The pool is scoped to one load, and CacheHandler remains unchanged unless a caller supplies the new optional hook factory.

Verification

  • Tests cover fresh and cached lists, value preservation, absent and non-string fields, plain CacheHandler behavior, and per-load pool lifetime.
  • Complete upstream suite: 473 passed; two unchanged dependency warnings.
  • Flake8 passes on all five changed files.

Synthetic comparison on Fedora 44 / Python 3.14.7: 18,000 logical records, two physical records each, five independent processes per case; values below are medians.

Path Metric Baseline Patched Change
Fresh retained traced allocation 40.4 MiB 26.3 MiB -34.9%
Fresh decode/model time 368 ms 452 ms +22.7%
Cached retained traced allocation 40.4 MiB 26.3 MiB -34.9%
Cached peak traced allocation 49.1 MiB 35.9 MiB -26.8%
Cached max RSS 146.9 MiB 99.0 MiB -32.6%
Cached decode/model time 373 ms 445 ms +19.3%

This is a synthetic scalability fixture, not a claim about whole-client RSS. The trade is a one-time decode cost for lower retained memory during the much longer server-list lifetime.

Development disclosure: I developed this patch with material assistance from OpenAI Codex under my direction, then reviewed, benchmarked, tested, and signed the final change.

Large server lists repeat immutable country, location, endpoint, generation,
and label strings across thousands of logical and physical server records.
Each decoded copy currently remains reachable through the model.

Share equal values within one server-list load. Apply the same policy after a
fresh HTTP decode and during cache JSON decoding, where it also lowers peak
allocation. Scope the pool to one load so it cannot retain obsolete lists.
Other CacheHandler users retain their existing behavior.

Tests cover fresh and cached data, value preservation, absent and non-string
fields, unchanged plain cache loads, and per-load pool lifetime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant