4 ms·
Recently there was a contest to optimize the performance of a similar program[0] and a Zoom discussion of the optimizations[1]. The programs are not comparable
by anonymoushn 4y ago
Recently there was a contest to optimize the performance of a similar program[0] and a Zoom discussion of the optimizations[1].
The programs are not comparable in the the following ways:
- Case: TFA requires (at least) ASCII lowercasing but the contest problem required no lowercasing.
- Ordering: TFA does not require sorting, but the contest problem required sorting.
- Memory: TFA imposes a requirement phrased as "don't read the whole file into memory" and this sounds like it's a resource-saving constraint, but it's usually a constraint that requires the program to spend additional resources. You could just mmap the file and store pointers into the mapped region. It costs extra to do copies instead of no copies.
- Text: TFA is unclear on what assumptions may be made about the lengths of words. For the contest problem, the Hungarian wikipedia input's longest word is around 80k.
- Safe, Hashing, Stdlib: TFA imposes some restrictions on what constructs may be used that are not imposed in the contest problem.
For the contest version of this problem, it seems like you can tokenize, hash, and count strings at around 1GB/s. Adapting a solution to solve TFA's problem (but not to conform to its Safe/Hashing/Stdlib requirements) would probably not carry too large of a penalty, since it's like 3 instructions to ASCII-lowercase 32 bytes and 1 string copy per unique string should take negligible time compared to the hash table lookups. So there is some room for the optimized solutions to go a little faster, if more optimizations are permitted.
[0]: https://easyperf.net/blog/2022/05/28/Performance-analysis-and-tuning-contest-6 https://easyperf.net/blog/2022/05/28/Performance-analysis-an...
[1]: https://www.youtube.com/watch?v=R_yX0XjdSBY https://www.youtube.com/watch?v=R_yX0XjdSBY