Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: only use cache when required #182

Merged
merged 3 commits into from
Nov 5, 2023

Conversation

KSXGitHub
Copy link
Contributor

No description provided.

@KSXGitHub KSXGitHub requested review from zkochan and anonrig November 4, 2023 16:55
Copy link

codecov bot commented Nov 4, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (2fb4bd4) 86.57% compared to head (1b55a89) 87.18%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #182      +/-   ##
==========================================
+ Coverage   86.57%   87.18%   +0.60%     
==========================================
  Files          56       56              
  Lines        2838     2824      -14     
==========================================
+ Hits         2457     2462       +5     
+ Misses        381      362      -19     
Files Coverage Δ
crates/cli/src/cli_args/add.rs 95.20% <100.00%> (ø)
crates/cli/src/cli_args/install.rs 94.44% <100.00%> (ø)
crates/cli/src/state.rs 97.56% <100.00%> (ø)
crates/package-manager/src/add.rs 97.50% <100.00%> (ø)
crates/package-manager/src/install.rs 82.75% <100.00%> (+0.94%) ⬆️
...ckage-manager/src/install_package_from_registry.rs 98.40% <100.00%> (+0.03%) ⬆️
...es/package-manager/src/install_without_lockfile.rs 100.00% <100.00%> (ø)
crates/tarball/src/lib.rs 90.81% <100.00%> (+1.08%) ⬆️
...tes/package-manager/src/install_frozen_lockfile.rs 0.00% <0.00%> (ø)
...package-manager/src/install_package_by_snapshot.rs 0.00% <0.00%> (ø)
... and 1 more

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

pub async fn run(self) -> Result<Arc<HashMap<OsString, PathBuf>>, TarballError> {
let &DownloadTarballToStore { tarball_cache, package_url, .. } = &self;
/// Execute the subroutine with cache.
pub async fn with_cache(
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
pub async fn with_cache(
pub async fn run_with_cache(

Copy link
Member

Choose a reason for hiding this comment

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

I agree, a function should be a verb.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a function should be a verb

BTW, Rust naming convention isn't like that.

let mut cache_write = cache_lock.write().await;
*cache_write = CacheValue::Available(Arc::clone(&cas_paths));
notify.notify_waiters();
Ok(cas_paths)
}
}

async fn without_cache(&self) -> Result<Arc<HashMap<OsString, PathBuf>>, TarballError> {
/// Execute the subroutine without a cache.
pub async fn without_cache(&self) -> Result<HashMap<OsString, PathBuf>, TarballError> {
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
pub async fn without_cache(&self) -> Result<HashMap<OsString, PathBuf>, TarballError> {
pub async fn run_without_cache(&self) -> Result<HashMap<OsString, PathBuf>, TarballError> {

Copy link

github-actions bot commented Nov 4, 2023

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
tarball/download_dependency    1.01      6.7±0.50ms   642.8 KB/sec    1.00      6.7±0.21ms   646.2 KB/sec

Copy link

github-actions bot commented Nov 4, 2023

Integrated-Benchmark Report (Linux)

Scenario: Frozen Lockfile

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 182.4 ± 17.0 155.9 205.4 1.03 ± 0.13
pacquet@main 176.5 ± 14.2 153.5 200.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18240761053666665,
      "stddev": 0.01702043888876676,
      "median": 0.17859883412,
      "user": 0.06913839000000001,
      "system": 0.10850109333333331,
      "min": 0.15587933012000002,
      "max": 0.20538548912000001,
      "times": [
        0.20538548912000001,
        0.17431539112000002,
        0.17490033312,
        0.20422093812,
        0.18229733512000001,
        0.15587933012000002,
        0.17337883312000002,
        0.19621883712000002,
        0.16110273112,
        0.18639313612000002,
        0.17058653312000002,
        0.20421243912
      ],
      "exit_codes": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.1764909955815385,
      "stddev": 0.01421546437258257,
      "median": 0.17504253412,
      "user": 0.0702174476923077,
      "system": 0.11147518307692308,
      "min": 0.15345723012,
      "max": 0.20062133812000002,
      "times": [
        0.17920653512,
        0.16898733212,
        0.17504253412,
        0.16804723212,
        0.18521073512000003,
        0.15541803012000002,
        0.18387913512,
        0.17286573312,
        0.19159913712,
        0.16710113312000002,
        0.20062133812000002,
        0.15345723012,
        0.19294683712000002
      ],
      "exit_codes": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    }
  ]
}

Copy link
Member

@zkochan zkochan left a comment

Choose a reason for hiding this comment

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

Why is it called a tarball cache at all? I had to look into the code because I thought it was about a filesystem cache for tarballs. I'd say it is a tarball_locker. And the function would be run_with_lock and run_without_lock.

pub async fn run(self) -> Result<Arc<HashMap<OsString, PathBuf>>, TarballError> {
let &DownloadTarballToStore { tarball_cache, package_url, .. } = &self;
/// Execute the subroutine with cache.
pub async fn with_cache(
Copy link
Member

Choose a reason for hiding this comment

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

I agree, a function should be a verb.

@KSXGitHub
Copy link
Contributor Author

KSXGitHub commented Nov 5, 2023

@zkochan lock would be even more ambiguous and misleading name than cache. Anyway, I have renamed the functions to run_with[out]_mem_cache and the tarball_cache fields to tarball_mem_cache (mem stands for "in-memory").

@zkochan zkochan merged commit ac9dbbd into main Nov 5, 2023
@zkochan zkochan deleted the refactor-only-use-cache-when-required branch November 5, 2023 11:08
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.

3 participants