Skip to content

Cache query file resolution to avoid repeated directory scans in hot query paths #409

@g105b

Description

@g105b

QueryFactory currently resolves query file paths by scanning the query directory with DirectoryIterator on each query lookup. In workloads that execute many small queries inside large loops, this repeatedly opens the same directory and re-scans its contents even when the query names are stable.

This is not necessarily the root cause of file descriptor exhaustion in consuming applications, but it does increase open-file churn and makes the library less efficient than it needs to be.

For directory-backed query collections, QueryFactory::findQueryFilePathInDirectory() iterates the directory on each query lookup:

  • src/Query/QueryFactory.php:59
  • src/Query/QueryFactory.php:66

That means repeated calls such as:

$db->fetchString("card/getSomething", $id);
$db->fetchString("card/getAnotherThing", $id);

will repeatedly re-open and scan the same card/ query directory

Metadata

Metadata

Assignees

Labels

performanceOptimisation or speed/memory improvements

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions