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

Sergey kornburn at yandex.ru
Sat Jan 13 23:20:32 UTC 2024


On Saturday, 13 January 2024 at 19:35:57 UTC, Renato wrote:
> On Saturday, 13 January 2024 at 17:00:58 UTC, Anonymouse wrote:
>> On Saturday, 13 January 2024 at 12:55:27 UTC, Renato wrote:
>>> [...]
> I will have to try it... I thought that `BigInt` was to blame 
> for the slowness (from what I could read from the trace logs), 
> but after replacing that with basically a byte array key (see 
> [commit 
> here](https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/0e9025b9aacdcfef5a2649be4cc82b9bc607fd6c)) it barely improved. It's still much slower than Common Lisp and very, very far from Java and Rust.

In the repo is hard to find the proper version.
I've checked the Rust from master branch and it looks a bit 
different from D implementation..

I would suggest to rewrite in the same way as Rust implemented.
Probably you would like to try:
* do not use BigInt from std. It could be quite slow. Try to use 
GMP library from Dub instead
* don't do "idup" every time
* instead of byLine, try byLineCopy
* instead of "arr ~= data" try to use Appender 
(https://dlang.org/library/std/array/appender.html)
* also you could try to use splitter 
(https://dlang.org/library/std/algorithm/iteration/splitter.html) 
to lazily process each part of the data
* isLastDigit function has many checks, but I think it could be 
implemented easier in a Rust way
* also consider to use functions from Range (filter, map) as you 
use it in Rust, instead of using for loops


More information about the Digitalmars-d-learn mailing list