zbraniecki / pluralrules

Pluralization handling in Rust
36 stars 4 forks source link

Use PHF for generated matches #20

Closed Manishearth closed 6 years ago

Manishearth commented 6 years ago

This improves performance of language rule fetching significantly. Not as much as I'd hoped, but 5x isn't too bad.

Instead of a giant match (which involves a lot of string comparisons), we use phf-map, which at compile time generates an efficient hash function that we can use with the statically generated map for fast lookup.

# before changes
test bench_create ... bench:         604 ns/iter (+/- 73)
test bench_total  ... bench:         943 ns/iter (+/- 159)

# after changes
test bench_create ... bench:         169 ns/iter (+/- 73)
test bench_total  ... bench:         819 ns/iter (+/- 235)
Manishearth commented 6 years ago

r? @unclenachoduh cc @zbraniecki

zbraniecki commented 6 years ago

This will require cargo regenerate-fixtures and cargo regenerate-fixtures-within - https://github.com/unclenachoduh/pluralrules/blob/master/make_pluralrules/.cargo/config

zbraniecki commented 6 years ago

Contributes to #14

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 106


Totals Coverage Status
Change from base Build 105: 0.03%
Covered Lines: 542
Relevant Lines: 603

💛 - Coveralls
unclenachoduh commented 6 years ago

Thanks for the PR @Manishearth. I updated the fixtures in https://github.com/unclenachoduh/pluralrules/pull/22 so this PR can be closed.