-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lipi] Increase performance by around 40%
Transliteration performance is not a bottleneck for anyone, but this commit applies a few simple optimizations that might be extended to other crates in this repo. Before: - `sample` runs in 13.49s After: - `sample` runs in 7.99s Benchmark changes: - Switch to transliterating millions of small strings as opposed to one enormous string. This seems like a more realistic workload. Transliteration changes: - Avoid looped map lookup and instead look up by the first char. - Avoid an extra hash lookup for a vowel mark. There is still one extra lookup remaining, but further iteration might remove this as well. Reshaping changes: - Avoid `collect` in favor of using a pre-allocated Vec. - If no changes were made, `Matcher` returns the original string without an extra allocation. - Avoid `match_2` and `take_2` logic in tight loops. Instead, fetch each char lazily and at most once. - `push_next` now increments an index so that we can push a whole sequence of chars at once. I also simplified the logic in `transliterate_inner`, but it's unclear how much of an effect that cleanup has.
- Loading branch information
Showing
7 changed files
with
235 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
use vidyut_lipi::{Lipika, Scheme}; | ||
|
||
fn main() { | ||
let mut input = String::new(); | ||
for _ in 0..1_000_000 { | ||
input.push_str(concat!( | ||
let mut lipika = Lipika::new(); | ||
|
||
for _ in 0..2_000_000 { | ||
let input = concat!( | ||
"nArAyaRaM namaskftya naraM cEva narottamam . ", | ||
"devIM sarasvatIM cEva tato jayamudIrayet .. 1 .." | ||
)); | ||
); | ||
lipika.transliterate(input, Scheme::Slp1, Scheme::Devanagari); | ||
} | ||
|
||
let mut lipika = Lipika::new(); | ||
let output = lipika.transliterate(input, Scheme::Slp1, Scheme::Devanagari); | ||
_ = lipika.transliterate(output, Scheme::Devanagari, Scheme::Slp1); | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.