-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caching strategy for stage1 #1416
Comments
I think that we should use Blake2b over sha256 -- it should be more performant. |
If you use this strategy for compilation targets in general, won't you have issues when you hit the cache limit and delete the oldest, but potentially most relied-upon libraries? Like if I have link all my targets to library A, but rarely recompile A from source, won't my project break depending on how cache eviction works? |
It looks like work has begun in stage1 -- I am excited. |
That's funny, I was just thinking about asking why not replace SHA-256 with BLAKE2b BEFORE reading the comments. :) Big thumbs up! Regarding performance: https://ziglang.org/download/0.2.0/release-notes.html :D Side-note: my favorites are ed25519, curve25519, poly1305, xsalsa20, blake2b, arc4random from OpenBSD, and of course constant-time functions including memzero, etc. I am not up-to-date with Zig's cryptography library, but I sure as hell will implement those in Zig when it's more mature! |
This landed a few weeks ago. |
Caching Strategy
This strategy is used for builds. This will cause
compiler_rt.o
,builtin.o
,zig build
scripts, andzig run
targets to be cached.Compilations have input parameters usually given by command line parameters. These are:
-isystem
,--name
,--release-fast
,-L
, etcBased on the SHA-256 hash of these parameters, this directory exists
(Replace
~/.local/share/zig
with the appropriate OS-specific directory):~/.local/share/zig/stage1/p30HdtbYqWz6O4RVkv99fxAupondYDfqK6VXjEacuSs/
Output artifacts (one or more of these):
./out/foo.o
./out/foo.obj
./out/foo.h
./out/foo.a
./out/foo.lib
./out/libfoo.so
./out/foo
./out/foo.exe
./out/advapi32.def
./out/builtin.zig
./out/foo.s
Manifest file:
./manifest
:this is so that if one of the files is modified, recomputing the hash
involves only processing the bytes of the modified file.
calculating the sha256 of that file can be skipped.
Cache Eviction
After adding files to the cache, calculate how many bytes were added.
Use file locking and use
~/.local/share/zig/stage1/size
as the storage for the byte count.If the byte count is greater than the configured cache size, look at all the directories
in
~/.local/share/zig/stage1/
and sort them by Least Recently Used on the mtime of themanifest
files. Delete entire directories until the byte count gets lower than the configured cache size.
Delete files from
~/.local/share/zig/stage1/
that are older than the oldest manifest mtime left.Default cache size: 10GB, user-configurable.
Compiler Id Cache
Contents of
~/.local/share/zig/stage1/zig/manifest
Has mtimes and sha256 and file paths. The sha256 is the id for that compiler, and refers
to, e.g.
~/.local/share/zig/stage1/zig/RLoSvwnmxxFm5LKJ5fND1UJ6uVOG1M-kgY7IWlNAS1w
Use file locking when modifying this file.
Contents of
~/.local/share/zig/stage1/zig/RLoSvwnmxxFm5LKJ5fND1UJ6uVOG1M-kgY7IWlNAS1w
This is recursively, the dynamic libraries that zig executable links against.
Bump the mtime on this file as well, after bumping the manifest file mtime, on a cache hit.
Benefits
zig build
andzig run
get especially fasterThe text was updated successfully, but these errors were encountered: