I wrote an AR archive (.a files) parser in D

Renato renato at athaydes.com
Tue Aug 20 19:53:40 UTC 2024


On Saturday, 17 August 2024 at 20:36:47 UTC, IchorDev wrote:
>
> Congrats! Which D compiler & flags did you use to test this BTW?
>

I've just [converted the 
code](https://github.com/renatoathaydes/dar/commit/c81daa297a523f93fafbe3564d36c15a52c04162) to use file random access, and it's about the same speed or maybe a bit slower than mmap.

Changing the D Code was as easy as it could be. No architectural 
changes required as something like Rust would definitely require.


I wasn't sure memory-mapped files would be faster, but it seemed 
easier to write the code based on that so I started with that... 
anyway, with random access (basically, `File.rawRead` and 
`File.seek`) it's a little harder to write, and the phobos lib is 
parsed in 0.110 secs with DMD (best of 3 tries, it varies a lot 
but second and third runs are much faster as I guess MacOS keeps 
the file's contents near memory?!), and 0.086 secs with LDC... 
very similar timings with the previous implementation, but that 
can go as low as 0.078 secs (within the "noise").

But using mmap was actually using a lot of memory, about as much 
memory as the size of the parsed file (~20MB) - perhaps I made a 
mistake the impl but I expected only the portion of the file I 
kept in memory at any time to remain in memory. With the random 
access impl, it used only 1.6MB of RAM.

Now, I am curious why D is so much faster than Dart (best time: 
1.2 secs - and the Dart code is not even handling the file names 
properly with the BSD variant, which costs time to do) :D. I've 
run benchmarks before where Dart was quite a bit faster when 
compiled to a binary executable (it was basically a deep tree 
allocation problem, Dart just seems to be able to allocate memory 
much faster than D).


More information about the Digitalmars-d mailing list