Re:Using D to Create the World’s Fastest File System
by WalterBright on Wednesday December 05, 2018 @03:28PM
(#18612177)
Two have told me they did so because D enabled them to write faster code than their competitors, and they were in a line of business where faster code meant making more money.
One reason D code is faster is array slicing, where you can refer to a subsection of an array. This pays off for things like strings. Consider the string:
s = "/root/me/file.ext";
I want to extract the "file" as a string. In C/C++, because strings are 0-terminated, I have a cache hit, allocate 5 bytes and copy 5 characters and install a 0. In D,
name = s[9 .. 13];
I have no cache hit, add 9 to a pointer, copy 5 to the length.
(A slice is equivalent to a (length, pointer) pair.)
One reason D code is faster is array slicing, where you can refer to a subsection of an array. This pays off for things like strings. Consider the string:
I want to extract the "file" as a string. In C/C++, because strings are 0-terminated, I have a cache hit, allocate 5 bytes and copy 5 characters and install a 0. In D, I have no cache hit, add 9 to a pointer, copy 5 to the length.(A slice is equivalent to a (length, pointer) pair.)