Add in-memory caching for directory reads#613
Conversation
Wrap getFilesInDirectory (C extension or Tcl fallback) with an in-memory cache keyed by directory path and fetch_dotversion flag. The cache lives for the duration of a single modulecmd process, avoiding redundant directory reads when the same directory is accessed multiple times during module resolution or overlapping search traversals. This reduces NFS round-trips on systems with thousands of modulefiles across deep directory structures. Signed-off-by: zapdos26 <zapdoskid@gmail.com>
Verify that the in-memory getFilesInDirectory cache returns correct results on repeated queries within a single invocation. Tests exercise cache population and cache hit paths. Signed-off-by: zapdos26 <zapdoskid@gmail.com>
…t env(TESTSUITE_MCOOKIE_CHECK) evalhide Signed-off-by: zapdos26 <zapdoskid@gmail.com>
|
Adding comments I got from Codex.
Details
|
|
Thanks @smprather for your comment and @zapdos26 for your change proposal. @zapdos26 could you to elaborate a bit on the redundant reads you mention.
The cache behavior of So from my understanding redundant reads should not be observed with existing code. |
|
I (via Codex) did some work on it. Unfortunately, I close on a new house tomorrow, and moving 5 miles down the road becomes my top-prio for a while. GPT fixed everything to make it CI-clean, including improving some false-failing tests (loosening some regex's). If there's no rush, I can provide the results as time permits. |
|
Codex said the performance improvement was minor, but it's there. @xdelaruelle : I'll feed in your question and see what it thinks. |
This pull request introduces an in-memory cache for directory reads in the
getFilesInDirectoryfunction to optimize performance by avoiding redundant reads during a single module command invocation. Additionally, a new test has been added to verify that the cache returns consistent results for repeated queries.Caching improvements:
getFilesInDirectoryfunction intcl/main.tcl.in, wrapping the original implementation and storing results for repeated directory queries within a single invocation.Testing enhancements:
testsuite/modules.90-avail/025-memcache.expto confirm that consecutiveavailqueries on the same module path return consistent results, validating the effectiveness of the cache.