Skip to content
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

Add support for an equivalent to ccache direct mode #219

Open
luser opened this issue Jan 19, 2018 · 2 comments
Open

Add support for an equivalent to ccache direct mode #219

luser opened this issue Jan 19, 2018 · 2 comments

Comments

@luser
Copy link
Contributor

luser commented Jan 19, 2018

ccache by default uses direct mode, where it doesn't run the preprocessor. This means that for local developers ccache is significantly faster than sccache. We should look into adding support for an equivalent mode to sccache, probably only when using local disk storage. From reading the linked docs there, it sounds like ccache hashes the input source file + compiler command line and uses that as a key to look up a cache entry which contains the list of included header files from the last compile and their hashes, and then validates all of those hashes. In ccache the object file is also available in this cache entry. For sccache we could either do that, or we could make direct cache misses just go through the existing preprocessor step, and then store the preprocessor hash in the direct cache entry.

@luser
Copy link
Contributor Author

luser commented Jan 19, 2018

cc @glandium @indygreg

@luser
Copy link
Contributor Author

luser commented Oct 21, 2019

I was looking at the ccache source for something else and I looked at how it implements direct mode.

When ccache gets preprocessor output, in addition to hashing it it also parses out included filenames and saves them:
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/ccache.cpp#L984

It writes a manifest file by calculating a hash derived from just compiler arguments and other info that doesn't require running the preprocessor (see calculate_result_name below):
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/ccache.cpp#L1201

Here's calculate_result_name function which is their equivalent to generate_hash_key. You can see that there are checks for direct_mode sprinkled through it:
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/ccache.cpp#L1859-L2152

All of the manifest code is in manifest.cpp. It stores a list of included files and some info about them, and a list of compile results which reference the included files they used:
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/manifest.cpp#L162

For each referenced file it stores the hash digest, file size and mtime/ctime:
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/manifest.cpp#L113

It looks like a manifest can contain multiple entries, each of which is a different compile, which is a little funky. Getting a cache hit involves calling verify_result to check that all the file hashes match:
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/manifest.cpp#L370-L453

When direct mode is enabled ccache calculates the manifest hash and looks to see if there's a manifest with a matching entry and if so
https://github.com/ccache/ccache/blob/8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464/src/ccache.cpp#L3847-L3870

I think if we were to implement this in sccache we'd probably want to make it conditional on only using local disk storage, and then annotate specific compiler arguments with whether they should be used in direct hash calculation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant