smhg / gettext-parser

Parse and compile gettext po and mo files, nothing more, nothing less
MIT License
158 stars 43 forks source link

speed up lexer parsing #88

Closed erikyo closed 2 months ago

erikyo commented 2 months ago

During the lexer parsing there are 2 cases that didn't require a regex (that is heavily costly compared to a chr/string comparison).

This small change provides an speed increased of about 20-25%.

Tested with benny

Running "Example" suite...
Progress: 100%

  gettextParser:
    6 631 ops/s, ±0.63%   | slowest, 23.54% slower

  gettextParserNext:
    8 673 ops/s, ±0.42%   | fastest

Finished 2 cases!
  Fastest: gettextParserNext
  Slowest: gettextParser
erikyo commented 2 months ago

I know it may sound like a breaking change but it is not, the regex in the end says exactly what a character comparison is (but much more costly). Additionally this task is performed for each translation block and the benefit is really high

image