Repository navigation
preprocessor cache: compare time-macro headers by content - #2954
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2954 +/- ##
==========================================
+ Coverage 80.03% 80.14% +0.11%
==========================================
Files 76 76
Lines 47506 47667 +161
==========================================
+ Hits 38021 38203 +182
+ Misses 9485 9464 -21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
edcb27c to
238b519
Compare
| if finder.found_timestamp() { | ||
| debug!("found __TIMESTAMP__ in {}", path.display()); | ||
| m.delimiter(b"timestamp"); | ||
| if let Ok(mtime) = std::fs::metadata(path).and_then(|meta| meta.modified()) { |
There was a problem hiding this comment.
the old code returned false when the mtime couldn't be read; here it silently drops the mtime, so a __TIMESTAMP__ header would match whatever its mtime. Is that intended?
There was a problem hiding this comment.
No, that wasn't intended. If the mtime can't be read the helper now returns None, and the lookup, remember_include_file and the entry key all treat that as a miss, like the old code did. Added a test for it, plus the doc comment and the SOURCE_DATE_EPOCH line.
| .collect() | ||
| }); | ||
|
|
||
| pub fn time_macro_adjusted_digest( |
There was a problem hiding this comment.
please add a short doc comment, it's pub and called from c.rs
| m.update(&date.year().to_le_bytes()); | ||
| m.update(&date.month().to_le_bytes()); | ||
| m.update(&date.day().to_le_bytes()); | ||
| if let Ok(source_date_epoch) = std::env::var("SOURCE_DATE_EPOCH") { |
There was a problem hiding this comment.
the comment explaining why we hash both SOURCE_DATE_EPOCH and the date got lost, could you please keep a one-line version?
238b519 to
f4be117
Compare
Merging this PR will improve performance by 8.81%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
f4be117 to
6343bf9
Compare
| return Ok(false); | ||
| } | ||
|
|
||
| let Some(file_digest) = time_macro_adjusted_digest(file_digest, &finder, &path) else { |
There was a problem hiding this comment.
time_macro_adjusted_digest stats the file with std::fs, not fs_impl, so the modified: None TestFs test only passes because the header doesn't exist on disk.
could we pass the mtime from meta here instead?
There was a problem hiding this comment.
The helper now takes the mtime as an argument, and remember_include_file passes meta.modified. The test writes the header to disk, so the only reason it gets refused is modified: None - it fails on the previous head. The lookup’s meta is a symlink_metadata while the entry key has none, so both still end up statting the file (following symlinks the same way remember_include_file’s meta does), and that only happens when it uses __TIMESTAMP__.
remember_include_file passes the mtime of the metadata it already read, so the unreadable-mtime test no longer depends on the header being absent from disk.
6343bf9 to
989282d
Compare
|
Thanks for your PR |
With
ignore_time_macrosoff, a header containing__DATE__or__TIMESTAMP__is never compared by content on lookup, so a same-size edit is served the old object:result_matchesskips the digest check once a time macro is found. The input's__TIMESTAMP__is not in the entry key either.Each remembered header is now stored and compared, and the input is keyed, by its content digest plus the date for
__DATE__and its mtime for__TIMESTAMP__; if that mtime can't be read the file is not cached. Files with neither keep their plain digest, so existing entries stay valid. Lookups no longer rewrite entries.Three new tests fail with the fix undone; two more drive
remember_include_file.