Repository navigation
Native {% blocktranslate %}, {% static %} and humanize naturaltime (0.4.0) - #8
Merged
Merged
Conversation
These three were the largest Python-bound pieces left on a realistic
backend+request page (benchmarks/realworld.py).
- {% blocktranslate %} / {% blocktrans %} compile to a native node
(src/tags/i18n.rs): count/context/with/trimmed/asvar, plural forms and
the stock missing-key and bad-format fallbacks. gettext, pgettext,
ngettext and npgettext go through a shared filters::Translator.
- {% static %} renders natively when handle_simple is stock. With the
exact StaticFilesStorage, storage.url results are memoized per
(base_url, path); other storages (Manifest, custom) still call url().
- humanize naturaltime is native. Msgids are read from the stock lazy
proxies rather than hardcoded (they contain U+00A0).
realworld page: 2.6x -> 3.5x over stock (2.9 ms -> 2.2 ms).
blocktranslate 1.1x -> 6-7x, static 1.3x -> 10x, naturaltime 1.2x -> 4.2x.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <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.
On a realistic backend+request page (
benchmarks/realworld.py), the three biggest Python-bound pieces left were{% blocktranslate %},{% static %}and humanize'snaturaltime. This PR makes all three native and bumps the version to 0.4.0.Changes
{% blocktranslate %}/{% blocktrans %}compile to a native node (src/tags/i18n.rs). It supportscount,context,with,trimmed,asvar, plural forms, and the stock fallbacks for missing keys and bad formats. A sharedfilters::Translatorhandles gettext, pgettext, ngettext and npgettext.{% static %}renders natively whenStaticNode.handle_simpleis the stock method. With the exact stockStaticFilesStorage,storage.urlresults are memoized per(base_url, path).setting_changeddropsbase_url, which changes the key. Other storages (Manifest, custom) still call their ownurl().naturaltimeis native. Its msgids are read from the stock lazy proxies instead of being hardcoded, because they contain U+00A0.Performance (pinned to an idle core, two runs each)
bench.py geomean: render 14.53x → 14.41x, compile 12.17x → 11.83x. Most rows are within noise. Repeated runs show two small but real render slowdowns:
inclusion_tag(about 4.45x → 4.2x) andcsrf_token_loop(about 12.1x → 11.5x). Neither path touches the new code. The new parse hooks reject other tags with a cached pointer-identity check, and the new payloads are boxed, soNodeis the same size. The most likely cause is code layout from the larger dispatch match. Worth a follow-up, but it doesn't block this PR.Testing
pytest: 1252 passed, in default, realpage-first and reversed file orders. This adds parity tests for blocktranslate, static (with and without staticfiles, threeSTATIC_URLs) and naturaltime (humanize_tests' fixed clock, naive, aware and odd tzinfo).cargo test --releasepasses.i18n,humanize_tests,timezones,forms_tests,admin_viewsandstaticfiles_teststhrough the Rust engine on 6.1: 100% (56,607 Rust renders).After merge: tag
v0.4.0on the merge commit to publish.🤖 Generated with Claude Code