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

feat(cli): check for updates in background #15974

Merged
merged 13 commits into from
Oct 20, 2022

Conversation

piscisaureus
Copy link
Member

No description provided.

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

This needs to be done in a way that doesn't impact startup time. It's too much overhead:

image

@piscisaureus
Copy link
Member Author

This needs to be done in a way that doesn't impact startup time. It's too much overhead:

image

Sure. How?

@bartlomieju
Copy link
Member

This needs to be done in a way that doesn't impact startup time. It's too much overhead:
image

Sure. How?

I think that check_for_upgrades() routine should be async and be called with tokio::spawn() using tokio::select!() with get_subcommand(flags).

@axetroy
Copy link
Contributor

axetroy commented Sep 21, 2022

This may not only increase startup time, but also cause unexpected network access. In some cases, security warnings may be triggered. (such as internal networks without Internet at all)

It is also a question whether Deno's cloud service will access the network every time when it is started.

@ry
Copy link
Member

ry commented Sep 22, 2022

What you can do is write an empty file $DENO_DIR/last_update_check. We can use the mtime of that file to log last update, allowing us to get away with just a single extra stat syscall.

I think that check_for_upgrades() routine should be async and be called with tokio::spawn() using tokio::select!() with get_subcommand(flags).

That won't work. We want to present "There's a new version 1.65.2" before anything else gets printed to stdout. Otherwise it will be quite confusing.

@bartlomieju
Copy link
Member

bartlomieju commented Sep 22, 2022

I think that check_for_upgrades() routine should be async and be called with tokio::spawn() using tokio::select!() with get_subcommand(flags).

That won't work. We want to present "There's a new version 1.65.2" before anything else gets printed to stdout. Otherwise it will be quite confusing.

I want to argue that startup time is way more important than printing this banner. We can have a cake and eat it too by doing the check in the background and printing the banner at the top on the subsequent run.

@littledivy
Copy link
Member

DenoDir::new is >40% of overall overhead even before the update checker starts up.

Even if DenoDir::new was fully optimized away, this PR will add enough overhead to overpower all optimizations suggested in #15945.

IMO we should reconsider doing this check & display in deno run and move it to some someplace where startup time does not matter (like deno eval / deno).

@piscisaureus
Copy link
Member Author

Was trying to optimize it this morning and I found that this PR does not meaningfully impact startup time.
Something else has made the main branch slower.

piscisaureus@dumbo:~/d/deno 🦕 hyperfine --warmup 2 'target/release/deno run a.js' 'target/release/deno_main run a.js'
Benchmark 1: target/release/deno run a.js
  Time (mean ± σ):      21.9 ms ±   0.4 ms    [User: 21.4 ms, System: 3.9 ms]
  Range (min … max):    21.3 ms …  23.9 ms    124 runs
 
Benchmark 2: target/release/deno_main run a.js
  Time (mean ± σ):      21.8 ms ±   0.3 ms    [User: 21.4 ms, System: 3.9 ms]
  Range (min … max):    21.4 ms …  22.7 ms    123 runs
 
Summary
  'target/release/deno_main run a.js' ran
    1.00 ± 0.02 times faster than 'target/release/deno run a.js'

@piscisaureus
Copy link
Member Author

I want to argue that startup time is way more important than printing this banner. We can have a cake and eat it too by doing the check in the background and printing the banner at the top on the subsequent run.

That's what is implemented in this patch.

@bartlomieju bartlomieju added this to the 1.26 milestone Sep 27, 2022
@bartlomieju bartlomieju removed this from the 1.26 milestone Sep 28, 2022
@bartlomieju bartlomieju self-assigned this Oct 14, 2022
@ry
Copy link
Member

ry commented Oct 15, 2022

Main branch vs this one. It appears this one is faster.

# hyperfine "deno run a.js" "./target/release/deno run a.js"
Benchmark 1: deno run a.js
  Time (mean ± σ):      26.5 ms ±   1.4 ms    [User: 21.6 ms, System: 4.4 ms]
  Range (min … max):    24.6 ms …  30.3 ms    95 runs

Benchmark 2: ./target/release/deno run a.js
  Time (mean ± σ):      19.9 ms ±   0.3 ms    [User: 20.8 ms, System: 4.0 ms]
  Range (min … max):    19.5 ms …  21.2 ms    129 runs

Summary
  './target/release/deno run a.js' ran
    1.33 ± 0.07 times faster than 'deno run a.js'

Tho it seems main startup time has gotten much worse than when @littledivy measured it. 26ms vs 13ms.

@littledivy
Copy link
Member

littledivy commented Oct 15, 2022

@ry that might be because this branch isn't uptodate with main. main had a regression after my measurements.

@bartlomieju bartlomieju added this to the 1.27 milestone Oct 15, 2022
@bartlomieju
Copy link
Member

Latest benchmark:

./third_party/prebuilt/mac/hyperfine --warmup 3 'target/release/deno run a.js' 'deno run a.js'
Benchmark #1: target/release/deno run a.js

  Time (mean ± σ):      16.7 ms ±   0.7 ms    [User: 16.2 ms, System: 6.3 ms]

  Range (min … max):    15.4 ms …  19.5 ms

Benchmark #2: deno run a.js

  Time (mean ± σ):      16.5 ms ±   3.5 ms    [User: 16.4 ms, System: 5.0 ms]

  Range (min … max):    13.8 ms …  33.8 ms

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary

  'deno run a.js' ran
    1.01x faster than 'target/release/deno run a.js'

@littledivy
Copy link
Member

+bench

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

⏳ Provisioning metal...

id: 7c95301c-4012-4cfe-a023-5a126b6316c6
metro: unknown

Use +bench status <id> for status

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

@denoland denoland deleted a comment from denobot Oct 19, 2022
@bartlomieju
Copy link
Member

Not finished yet; I'll push changes that limit number of syscalls used today.

@bartlomieju
Copy link
Member

+bench

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

⏳ Provisioning metal...

id: c6db2518-762b-4f53-92b9-acef3561ec6e
metro: unknown

Use +bench status <id> for status

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

Command Mean [ms] Min…Max [ms]
deno run equinix-metal-test/nop.js 13.0 ± 2.4 11.6…20.6
./deno run equinix-metal-test/nop.js 12.4 ± 0.2 12.0…13.0

@bartlomieju
Copy link
Member

+bench

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

⏳ Provisioning metal...

id: 6f04148f-cd14-4ada-bc98-6d402d897c64
metro: unknown

Use +bench status <id> for status

@littledivy
Copy link
Member

+bench status 6f04148f-cd14-4ada-bc98-6d402d897c64

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

✅ Device provisioned 91%

metro: Silicon Valley (US)

@denobot
Copy link
Collaborator

denobot commented Oct 19, 2022

Command Mean [ms] Min…Max [ms]
deno run equinix-metal-test/nop.js 12.0 ± 0.2 11.5…12.5
./deno run equinix-metal-test/nop.js 12.3 ± 0.3 11.9…14.7

@denoland denoland deleted a comment from denobot Oct 19, 2022
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

We should fix how we get the cache directory.

@bartlomieju
Copy link
Member

@dsherret addressed the feedback, I changed the checker to only run with deno run (discussed with Ry offline)

@bartlomieju bartlomieju requested a review from dsherret October 19, 2022 20:52
@bartlomieju bartlomieju requested a review from ry October 20, 2022 11:49
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

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.

7 participants