Cache validity file path and parsed Catalog in .on() to eliminate redundant I/O#47
Draft
Cache validity file path and parsed Catalog in .on() to eliminate redundant I/O#47
Conversation
…filesystem calls Co-authored-by: gipert <20358192+gipert@users.noreply.github.com>
Co-authored-by: gipert <20358192+gipert@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize .on() method by reducing filesystem calls
Cache validity file path in .on() to eliminate redundant filesystem lookups
Feb 14, 2026
Owner
|
@copilot the method is still slow. what is the bottleneck? |
Co-authored-by: gipert <20358192+gipert@users.noreply.github.com>
Author
The bottleneck was Performance improvement:
The first call takes ~4.7ms (includes parsing and caching), but subsequent calls are dramatically faster since they skip both filesystem I/O and YAML parsing. |
Copilot
AI
changed the title
Cache validity file path in .on() to eliminate redundant filesystem lookups
Cache validity file path and parsed Catalog in .on() to eliminate redundant I/O
Feb 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
.on()method performed filesystem checks (4×is_file()calls per invocation) to locate the validity file on every query, and then parsed the YAML/JSON validity file on every call. This is wasteful since both the validity file location and content are static for a given database instance.Implementation
__validity_file__attribute: Caches thePathto validity file after first lookup__catalog__attribute: Caches the parsed Catalog object to avoid re-parsing YAML/JSON_find_validity_file()helper: Encapsulates search logic, sets cache, and parses the validity file.on()method: Uses cached catalog (self.__catalog__.valid_for()) instead of re-parsingreset()method: Clears both caches when database state changes__validity_file__and__catalog__stateBehavior
Performance Impact
.on()callThe bottleneck was
Catalog.read_from()which parsed the YAML/JSON validity file on every call (~70% of execution time). By caching the parsed Catalog object, subsequent calls skip both filesystem I/O and parsing operations.The optimization eliminates repeated I/O and parsing without changing the API or behavior.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.