compile time compression for associatve array literal

Brian Tiffin btiffin at gnu.org
Mon Aug 23 19:57:33 UTC 2021


On Monday, 23 August 2021 at 14:49:17 UTC, jfondren wrote:
> On Monday, 23 August 2021 at 14:04:05 UTC, Brian Tiffin wrote:
>> That's the goal.  It's an optional goal at this point.  I'm 
>> not *really* worried about size of object code, yet, but 
>> figured this would be a neat way to shrink the compiled code 
>> generated from some large COBOL source fragments embedded in D 
>> source.
>
> The decompression needs to happen at runtime, where these 
> libraries are still useful. The compression could happen 
> through CTFE once some suitable compression code is written in 
> D, but that's not actually required to get the results of
>
> 1. your object file contains compressed strings
>
> 2. your program decompresses them at runtime
>
> You can still achieve this end by having your build system 
> compress external files that D then includes.
>
> Manually setting this up:
>
> ```
> $ dd if=/dev/zero bs=$((1024*1024)) count=1024 of=gigabyte.data
> 1024+0 records in
> 1024+0 records out
> 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.3655 s, 786 MB/s
>
> $ time zip giga.zip gigabyte.data
>   adding: gigabyte.data (deflated 100%)
>
> real    0m5.645s
> user    0m5.470s
> sys     0m0.160s
>
> $ du -sh giga.zip
> 1020K   giga.zip
>
> $ dmd -J. -O zeroes.d
>
> $ du -sh zeroes
> 3.3M    zeroes
>
> $ time ./zeroes > out.data
>
> real    0m3.310s
> user    0m1.486s
> sys     0m1.167s
>
> $ diff -s gigabyte.data out.data
> Files gigabyte.data and out.data are identical
> ```
>
> From this zeroes.d:
>
> ```d
> import std.stdio : write;
> import std.zip;
>
> enum zeroes = import("giga.zip");
>
> void main() {
>     auto zip = new ZipArchive(cast(char[]) zeroes);
>     ArchiveMember am = zip.directory.values[0];
>     zip.expand(am);
>     write(cast(char[]) am.expandedData);
> }
> ```

Yep, pondered external tooling, but that's not a goal either 
really.  Want people, well me actually, looking at the source 
file to be able to quickly scan over the fragments from the 
single D source.  I'm still ok with high-school level D at this 
point, and will just compile in the heredoc strings, as-is.

And thanks, jfondren.  Making another bookmark for later visiting 
once further up the D curve.

Cheers


More information about the Digitalmars-d-learn mailing list