Skip to content

Cache IO plugin discovery instead of rescanning for every handler - #2156

Merged
zariiii9003 merged 2 commits into
hardbyte:mainfrom
Solarboaters:fix/cache-io-plugin-discovery
Nov 26, 2026
Merged

zariiii9003 merged 2 commits into
hardbyte:mainfrom
Solarboaters:fix/cache-io-plugin-discovery

Conversation

@Solarboaters

@Solarboaters Solarboaters commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Restore caching of successful reader/writer plugin discovery, following the approach proposed in #2155. Repeated Logger() / LogReader() construction currently scans installed entry points every time, even when no plugins exist.

The two regression checks now live in the existing ReaderWriterExtensionTest. Each warms up a public factory, then verifies that three more handler constructions do not rescan entry points. They do not depend on cache internals or fake plugins. Both fail against the original production implementation and pass with the fix.

Validation after the review update:

  • tox -e py: 676 passed, 126 skipped, 43 subtests passed on Python 3.12.
  • Formatting and git diff --check pass. This update changes only tests; the earlier production revision passed tox -e lint,type,docs using Python 3.14.
  • Five runs of 100 real ASC handler constructions/stops in the same Python 3.12 environment: median Logger time 5.83 → 0.059 ms/call, LogReader 5.29 → 0.032 ms/call. These are local factory timings, not a hardware recording benchmark.

The initial scan still costs time. functools.cache can also run the initial function more than once for simultaneous cold calls; this patch removes repeated scans after discovery, without adding a locking policy. I have not claimed to reproduce or eliminate the reporter's nine-bus frame loss.

Fixes #2155's repeated-discovery regression. Prepared with AI assistance; the tests and measurements were executed locally.

@zariiii9003

Copy link
Copy Markdown
Collaborator

AI Review: Cache IO plugin discovery (#2156)

Context

Tests

  • The test belongs in an existing file (test/test_io_plugin_cache.py): ReaderWriterExtensionTest in test/logformats_test.py already tests how can.Logger() / can.LogReader() pick a class. Fix: move the test there and delete the new file.
  • The test is tied to how the cache works (cache_clear(), the patched read_entry_points name per module, plugin.load call count): switching to a flag or adding a lock would break it although behaviour is unchanged. Fix: per factory, make one warm-up call, then patch can._entry_points.entry_points and assert three more calls never scan; drop the fake plugin and the with_plugin parameter.

Verdict

request changes

@Solarboaters

Copy link
Copy Markdown
Contributor Author

Thanks — agreed. I moved the two factory checks into ReaderWriterExtensionTest and removed the separate file. Each warms up the factory, then checks that three further calls do not scan entry points; there is no cache clearing or fake plugin. Both fail against the original implementation and pass with the fix. tox -e py passes: 676 tests, 126 skips and 43 subtests; formatting also passes. Updated in 1ac4dbd.

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@zariiii9003
zariiii9003 merged commit 71fcefc into hardbyte:main Nov 26, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance regression: Logger()/LogReader() factories re-scan all entry_points on every construction since 4.4.0 (plugin cache guard was dropped)

2 participants