Summary
The application repeatedly reads and parses the JSON configuration (File::loadConfig and related helpers) on many code paths (e.g., getCommandIndex, interactiveSearch). Re-parsing and reloading the config for frequent operations adds CPU and I/O overhead, especially for large configurations or when performing many interactive searches in a session.
Reproduction / evidence
- src/loadfile.cpp: File::getCommandIndex calls loadConfig() at the start of the function. Similar patterns appear in other call sites that run during interactive flows.
Impact
- Increased latency when listing/searching commands or when the CLI performs frequent operations.
- Unnecessary disk I/O and CPU usage for repeated JSON parsing.
Suggested fixes / improvements
-
Implement an in-memory config cache:
- Load and parse the configuration once at startup or on first access and keep it in memory.
- Invalidate and reload the cache only when the config file changes (watch file mtime or provide an explicit reload API).
-
Use incremental updates for small modifications:
- When the program modifies a single command or alias, update the in-memory structure and persist the change rather than reloading the entire file.
-
Reduce JSON parsing overhead:
- Consider using a faster JSON library or enable streaming parsing for large files. Profile current parsing to determine hotspots.
Files/places to review first
- src/loadfile.cpp (loadConfig, saveConfig, getCommandIndex)
- Any code that calls loadConfig frequently during interactive flows
Severity: medium
Summary
The application repeatedly reads and parses the JSON configuration (File::loadConfig and related helpers) on many code paths (e.g., getCommandIndex, interactiveSearch). Re-parsing and reloading the config for frequent operations adds CPU and I/O overhead, especially for large configurations or when performing many interactive searches in a session.
Reproduction / evidence
Impact
Suggested fixes / improvements
Implement an in-memory config cache:
Use incremental updates for small modifications:
Reduce JSON parsing overhead:
Files/places to review first
Severity: medium