Implement embedding a Trinary Search Tree
It is good for a lot of small files - fill the tree, GOB encode, gzip then store as base64 in the source.
On init, the code decodes the base64, uncompresses, decodes, then fills the names slice and the values map from the tree.
Benchmarks with the zoneinfo.zip:
$ rm zoneinfo/.go; time embedfiles -out zoneinfo/zi.go -pkg=tz -trie=false zoneinfo/ ; ls -l zoneinfo/.go real 0m1,276s user 0m1,599s sys 0m0,033s -rw-r--r-- 1 gthomas gthomas 2721295 jan 25 15:51 zoneinfo/zi.go
$ rm zoneinfo/.go; time embedfiles -out zoneinfo/zi.go -pkg=tz -trie=true zoneinfo/ ; ls -l zoneinfo/.go real 0m0,045s user 0m0,031s sys 0m0,019s -rw-r--r-- 1 gthomas gthomas 295428 jan 25 15:51 zoneinfo/zi.go
So a tenfold decrease in source size.
Hi @tgulacsi, wow thanks for optimizing how the files are stored. I wouldn't have expected such a huge time and space saving, but I guess it makes sense as I'm not really doing anything for performance.
Do you know how much benefit we get from using only one or the other? i.e. Does gzipping the files by itself cause a significant speed benefit as well, or is the speed benefit all from the TST?
The fastest and less memory consuming would be to uncompress only when retrieving the file - so no map, just the file name list, and a function to retrieve (decode & uncompress) the data (zoneinfo).