django-ftl / fluent-compiler

High performance Python implementation of Fluent, Mozilla's l10n language
Other
21 stars 4 forks source link

Use f-strings for string joining #2

Closed spookylukey closed 4 years ago

spookylukey commented 4 years ago

In Python 3.6 and later, the fastest way to join strings is f-string, or ast.JoinedStr at AST level. Last time I experimented, doing f'text {item}' got about 10% speed improvement over using ''.join("text ", item) for the case of a message with a single interpolation.

Should be straightforward to modify StringJoin to do this, the hardest part is testing when we have to support Python 3.5 and Python 2.7. Probably we want a mechanism to switch it off for most of the tests, so that we don't have to change lots of tests.