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

The first run after each new Zeabur deployment is always quite slow (takes 10+ secs) #49

Closed
laike9m opened this issue Nov 20, 2023 · 4 comments

Comments

@laike9m
Copy link
Owner

laike9m commented Nov 20, 2023

It seems pretty reproducible, but I'm not sure if this is our problem or theirs

@laike9m
Copy link
Owner Author

laike9m commented Nov 27, 2023

I added some logging:

0_check_with_pyright_start: "01:34:10.683"
1_pyright_run_start: "01:34:10.684"
2_pyright_run_end: "01:34:38.457"

Logging is added in

time_table["1_pyright_run_start"] = get_current_time()
raw_result = subprocess.run(
["pyright", "--pythonversion", "3.12", temp.name],
capture_output=True,
text=True,
).stdout
time_table["2_pyright_run_end"] = get_current_time()
error_lines: list[str] = []

It's clear that pyright takes 28s to finish!

Given subsequent runs take significantly less time, I think this is due to pyright needs to generate indexes and cache the first time it runs.

Given we don't really need to analyze third-party libraries installed in the virtualenv (which pyright does by default), I'll see how can we disable this behavior.

@laike9m
Copy link
Owner Author

laike9m commented Nov 27, 2023

Further adding --stats to pyright gives and reran

Overall takes ~27s

1_pyright_run_start: "02:18:28.676"
2_pyright_run_end: "02:18:55.150"

Detailed:

added 1 package, and audited 2 packages in 14s

found 0 vulnerabilities
Loading pyproject.toml file at /app/pyproject.toml
Found 1 source file
pyright 1.1.334
/tmp/tmpn3_n1gxk.py
  /tmp/tmpn3_n1gxk.py:13:8 - error: Expected 1 positional argument (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations 
Completed in 1.903sec

Analysis stats
Total files parsed and bound: 18
Total files checked: 1

Timing stats
Find Source Files:    0sec
Read Source Files:    0.08sec
Tokenize:             0.14sec
Parse:                0.32sec
Resolve Imports:      0.18sec
Bind:                 0.58sec
Check:                0.06sec
Detect Cycles:        0sec
WARNING: there is a new pyright version available (v1.1.334 -> v1.1.337).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

So out of 27s, installing node packages takes 14s, analyzing takes 2s. It's still unclear where the other 10s is spent on, but at least we know installing node packages is the biggest contributor to slow run

@laike9m
Copy link
Owner Author

laike9m commented Nov 27, 2023

Reading https://github.com/microsoft/pyright/blob/main/docs/configuration.md, I can't find any option to pre-install node_modules. It mentions ignoring files when analyzing, but since we only checked one file (see above), I don't think this will help.

Given that, seems the only way is to simply pre-run pyright upon server start, to warm things up.

@laike9m
Copy link
Owner Author

laike9m commented Nov 27, 2023

Tested on the debug branch and it worked well.

laike9m added a commit that referenced this issue Nov 27, 2023
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

No branches or pull requests

1 participant