Help optimize D solution to phone encoding problem: extremely slow performace.
Renato
renato at athaydes.com
Wed Jan 17 07:06:25 UTC 2024
On Tuesday, 16 January 2024 at 22:15:04 UTC, Siarhei Siamashka
wrote:
> On Tuesday, 16 January 2024 at 21:15:19 UTC, Renato wrote:
>> For the record (I already posted this on GitHub)... here's [my
>> current fastest
>> solution](https://github.com/renatoathaydes/prechelt-phone-number-encoding/blob/dlang-key-hash-incremental/src/d/src/dencoder.d) time using the same algorithm as Rust ...
>
> [...]
>
>> ... what I am really curious about is what the code I wrote is
>> doing wrong that causes it to run 4x slower than Rust despite
>> doing "the same thing"...
>
> It's a GC allocations fest. Things like this make it slow:
>
> ```diff
> {
> - string digit = [digits[0]];
> + string digit = digits[0 .. 1];
> words.insertBack(digit);
> ```
I was under the impression that `[digits[0]]` would just use a
stack allocation??
The profiler does not show any GC anymore, are you sure it's a
"GC allocations fest"???
> And at the top is the associative array lookup (when profiling
> the handling of the "phones_1_000_000_with_empty.txt" input
> file):
>
> ```
> 36.85% dencoder dencoder [.] _aaInX
> 12.38% dencoder dencoder [.] void
Well, I know, but I did everything to make the hash "cheap" to
compute so I still don't see a way to improve it.
More information about the Digitalmars-d-learn
mailing list