File Index
MicPy uses an indexing mechanism to significantly improve the performance of reading binary files. When a binary file is opened, MicPy scans its structure and builds an in-memory index that maps the file’s fields and their locations. This allows the library to access individual fields efficiently without repeatedly traversing the file.
In addition to the in-memory index, MicPy attempts to persist the index to disk. Once created, the index is saved alongside the binary file using the same name with an additional .idx extension. When the file is opened again, MicPy automatically loads the existing index if it is available and valid, eliminating the need to rebuild it.
This design provides two key advantages:
- Fast field access at runtime through the in-memory index.
- Reduced startup time on subsequent opens by reusing the on-disk index.
The index file is tightly coupled to the binary file it was generated from. If the binary file has changed, MicPy will detect the mismatch and regenerate the index to ensure correctness.
This combined in-memory and persistent indexing strategy ensures predictable read performance while keeping indexing overhead to a minimum.