Help optimize D solution to phone encoding problem: extremely slow performace.

H. S. Teoh hsteoh at qfbox.info
Sat Jan 20 01:27:50 UTC 2024


On Sat, Jan 20, 2024 at 01:35:44AM +0100, Daniel Kozak via Digitalmars-d-learn wrote:
[...]
>    > Try addressing the points I wrote above and see if it makes a
>    > difference.
> 
>    I have tried it (all of it) even before you wrote it here, because
>    I have completely the same ideas, but to be fair it has almost zero
>    effect on speed.
>    There is my version (It still use OOP, but I have try it wit
>    Printer and Counter to be structs and it has no effect at
>    all) [2]https://paste.ofcode.org/38vKWLS8DHRazpv6MTidRJY
>    The only difference in speed in the end is caused by hash
>    implementation of dlang associative arrays and rust HashMap,
>    actually if you modify rust to not used ahash it has almost same
>    speed as D
[...]

I'm confused by the chained hashing of the digits. Why is that
necessary?  I would have thought it'd be faster to hash the entire key
instead of computing the hash of each digit and chaining them together.

I looked up Rust's ahash algorithm. Apparently they leverage the CPU's
hardware AES instruction to compute a collision-resistant hash very
quickly.

Somebody should file a bug on druntime to implement this where the
hardware supports it, instead of the current hashOf. For relatively
small keys this would be a big performance boost.


T

-- 
Valentine's Day: an occasion for florists to reach into the wallets of nominal lovers in dire need of being reminded to profess their hypothetical love for their long-forgotten.


More information about the Digitalmars-d-learn mailing list