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

Initializing octocrab takes 300ms on macOS #396

Open
raine opened this issue Jun 15, 2023 · 11 comments
Open

Initializing octocrab takes 300ms on macOS #396

raine opened this issue Jun 15, 2023 · 11 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@raine
Copy link

raine commented Jun 15, 2023

Any ideas what could make it this slow? From a quick glance to the code I couldn't see anything obvious.

It should be just building a http client, correct?

let start = std::time::Instant::now();
let client = octocrab::Octocrab::builder()
    .personal_token(site_config.oauth_token.to_string())
    .build()?;
octocrab::initialise(client);
let elapsed = start.elapsed();
println!("Elapsed: {} ms", elapsed.as_millis());

Output

Elapsed: 330 ms
@XAMPPRocky
Copy link
Owner

Thank you for your issue! No I'm not aware of anything. You might want to use something like cargo-flamegraph to see exactly what is taking up time

@theRookieCoder
Copy link

theRookieCoder commented Aug 6, 2023

I can confirm this is a problem with octocrab. My hyperfine results went from

> hyperfine 'ferium list'
Benchmark 1: ferium list
  Time (mean ± σ):     405.0 ms ±   4.5 ms    [User: 240.5 ms, System: 31.1 ms]
  Range (min … max):   398.9 ms … 413.0 ms    10 runs

to

> hyperfine 'ferium list'
Benchmark 1: ferium list
  Time (mean ± σ):      16.9 ms ±   2.2 ms    [User: 7.5 ms, System: 6.4 ms]
  Range (min … max):    13.3 ms …  24.8 ms    124 runs

by just commenting out the octocrab initialisation, there were no other modifications. This is on the latest version 0.29.1 and I've been having this problem for a while at this point. It's very noticeable in use too.

@theRookieCoder
Copy link

theRookieCoder commented Aug 6, 2023

Also I wasn't able to run flamegraph because it doesn't seem to work on macOS?

@XAMPPRocky
Copy link
Owner

@theRookieCoder Im pretty sure it does given their documentation mentions it and I have used it before on macOS.

You might want to make sure you're running as superuser. https://github.com/flamegraph-rs/flamegraph#dtrace-on-macos

@theRookieCoder
Copy link

Screenshot 2023-08-06 at 11 24 12 PM

full flamegraph

Looks to me like some sort of macOS process is taking a ton of time, I wonder if this replicates on linux and windows.

@XAMPPRocky
Copy link
Owner

XAMPPRocky commented Aug 6, 2023

Interesting, I wonder what's calling that, we don't use that directly, so I have to assume it's some https thing.

@XAMPPRocky
Copy link
Owner

@raine Were you also on macOS?

@raine
Copy link
Author

raine commented Aug 11, 2023

Yes

@XAMPPRocky XAMPPRocky changed the title Initializing octocrab takes 300ms Initializing octocrab takes 300ms on macOS Aug 11, 2023
@XAMPPRocky XAMPPRocky added bug Something isn't working help wanted Extra attention is needed labels Aug 11, 2023
@JeanMertz
Copy link
Contributor

Here is an image of a trace.

It shows this is coming from rustls which calls load_native_certs, which, for macOS, means going into the keychain and fetching a list. I don't know why this is slow, it might be that the APIs to fetching this data in the keychain is slow, or it might that rustls is doing something wrong here.

See also:

Screenshot 2023-08-24 at 11 16 07

@raine
Copy link
Author

raine commented Aug 26, 2023

My needs were quite modest so I solved the problem by writing a small Github client from scratch with reqwest, which for some reason does not have this delay. Perhaps it uses native tls instead of rustls.

@lucacasonato
Copy link

Can you try running with features = ["rustls-webpki-tokio"]? This should bypass loading of native certs, and instead use a bundled Mozilla trust chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants