Skip to content

Conversation

@tstack
Copy link
Contributor

@tstack tstack commented Oct 7, 2025

Scanning the source hierarchy and extracting log statements is pretty costly, so we need to cache what we found between runs. This change writes a separate file for every source root. The file contains a header that is a JSON-line with interesting metadata that a user might find helpful. The body of the file is a bincode serialization of the SourceTree object. The CLI will try to load from the cache on startup, check for any changes in the source tree, and then update the cache, if necessary.

I was originally looking at using SQLite for the cache, but it's hard to write blobs of unknown size to a table. This approach seems to work since the header can easily be read separately from the main content to determine if the file is valid or not. I also tried using the postcard
serializer, but had trouble getting it to work. The bincode one seems to just work.

Files:

  • Cargo.toml: Add some more dependencies:
    • bincode for serialization
    • directories for finding the user's platform-specific cache directory
    • serde_regex for serializing/deserializing Regex
    • sha2 for producing a hash used for the cache file names
    • tempfile for creating the cache file
    • walkdir for walking the cache dir in the tests
  • cache-header-v1.json: The schema for the cache entry header
  • lib.rs: Add cache stuff
  • main.rs: Add a footer to the help to mention where the cache is. Load the statements from the cache and save for future use.
  • source_hier.rs: Derive Deserialize on various structs.
  • common_settings/mod.rs: Move helper module to its own directory.
  • source_ref.rs: Serialize/deserialize the Regex directly so the deserialize can fail if the regex string is invalid. Add separate pattern_str to cache the string version of the pattern.

tstack added 7 commits October 7, 2025 11:22
Scanning the source hierarchy and extracting log statements 
is pretty costly, so we need to cache what we found between
runs.  This change writes a separate file for every source
root.  The file contains a header that is a JSON-line with
interesting metadata that a user might find helpful.  The
body of the file is a bincode serialization of the
SourceTree object.  The CLI will try to load from the cache
on startup, check for any changes in the source tree, and
then update the cache, if necessary.

I was originally looking at using SQLite for the cache, but
it's hard to write blobs of unknown size to a table.  This
approach seems to work since the header can easily be read
separately from the main content to determine if the file
is valid or not.  I also tried using the postcard
serializer, but had trouble getting it to work.  The
bincode one seems to just work.

Files:
* Cargo.toml: Add some more dependencies:
  - bincode for serialization
  - directories for finding the user's platform-specific
    cache directory
  - serde_regex for serializing/deserializing Regex
  - sha2 for producing a hash used for the cache file names
  - tempfile for creating the cache file
  - walkdir for walking the cache dir in the tests
* cache-header-v1.json: The schema for the cache entry
  header
* lib.rs: Add cache stuff
* main.rs: Add a footer to the help to mention where the
  cache is.  Load the statements from the cache and save
  for future use.
* source_hier.rs: Derive `Deserialize` on various structs.
* common_settings/mod.rs: Move helper module to its own
  directory.
* source_ref.rs: Serialize/deserialize the Regex directly
  so the deserialize can fail if the regex string is
  invalid.  Add separate `pattern_str` to cache the
  string version of the pattern.
If running with "-v", log that the cache will not be used
cmd.env("XDG_CONFIG_HOME", self.location.path());
cmd.env("USERPROFILE", self.location.path());
cmd.env("LOCALAPPDATA", self.location.path());
cmd.env("APPDATA", self.location.path());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ProjectDirs need TEMP or TMP set to work on windows? That was one recommendation by the coding assistant on how to fix this...

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

Successfully merging this pull request may close these issues.

2 participants