Skip to content

Singleflight Python health checks with cached interpreter info#1381

Merged
j178 merged 2 commits intomasterfrom
python-cache
Jan 17, 2026
Merged

Singleflight Python health checks with cached interpreter info#1381
j178 merged 2 commits intomasterfrom
python-cache

Conversation

@j178
Copy link
Owner

@j178 j178 commented Jan 17, 2026

Add singleflight caching for Python interpreter info to dedupe parallel health checks.

Add singleflight caching for Python interpreter info to dedupe parallel health checks.
@j178 j178 added the enhancement New feature or request label Jan 17, 2026
@j178 j178 requested a review from Copilot January 17, 2026 10:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds singleflight caching for Python interpreter information queries to prevent duplicate work when multiple health checks run in parallel. The implementation uses the uv-once-map crate to ensure only one query executes at a time for each Python interpreter path.

Changes:

  • Introduced a global cache (PYTHON_INFO_CACHE) using OnceMap to deduplicate concurrent Python info queries
  • Created new query_python_info_cached function that wraps the existing query logic with caching
  • Updated check_health methods in Python and Pygrep language implementations to use the cached version

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/prek/src/languages/python/python.rs Added caching infrastructure with OnceMap, implemented query_python_info_cached function, and updated check_health to use cached queries
crates/prek/src/languages/python/mod.rs Updated exports to replace query_python_info with query_python_info_cached
crates/prek/src/languages/pygrep/pygrep.rs Updated check_health to use query_python_info_cached
crates/prek/Cargo.toml Added uv-once-map dependency
Cargo.toml Added uv-once-map version constraint
Cargo.lock Lock file updates for new dependencies
.pre-commit-config.yaml Added trailing-whitespace check hook

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Jan 17, 2026

📦 Cargo Bloat Comparison

Binary size change: -0.44% (22.5 MiB → 22.4 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 71.5KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 53.8KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 49.9KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.5% 42.3KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.6KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 29.2KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.6KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 21.0KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.7KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::languages::python::uv::InstallSource::install::{{closure}}
36.7%  91.7%  8.2MiB              And 19721 smaller methods. Use -n N to show more.
40.0% 100.0%  9.0MiB              .text section size, the file size is 22.4MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 72.4KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 54.7KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 49.9KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.0KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.0KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.6KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.4KiB        prek? <prek::cli::Cli as clap_builder::derive::FromArgMatches>::from_arg_matches_mut
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.7KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
36.6%  91.6%  8.2MiB              And 19827 smaller methods. Use -n N to show more.
39.9% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.30%. Comparing base (52c20ab) to head (5d8da4a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/languages/python/python.rs 70.83% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1381      +/-   ##
==========================================
- Coverage   90.34%   90.30%   -0.04%     
==========================================
  Files          81       81              
  Lines       16122    16143      +21     
==========================================
+ Hits        14565    14578      +13     
- Misses       1557     1565       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@j178 j178 merged commit 414d0cc into master Jan 17, 2026
25 checks passed
@j178 j178 deleted the python-cache branch January 17, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant