Skip to content

Comments

Add basic red knot benchmark#13026

Merged
MichaReiser merged 4 commits intomainfrom
knot-mypy-pyright-benchmarks
Aug 23, 2024
Merged

Add basic red knot benchmark#13026
MichaReiser merged 4 commits intomainfrom
knot-mypy-pyright-benchmarks

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Aug 21, 2024

Summary

This PR adds a basic benchmark runner for red knot. These benchmarks are different from codspeed in that they benchmark
entire projects. They are not micro-benchmarks.

The benchmarks aren't representive! Don't draw any conclusion from them today.
Red Knot only implements a tiny tiny subset of Mypy's and Pyright's functionality.

This work is inspired by mypy primer but it serves
a different purpose. We may want to add Red Knot to mypy primer when we have a more complete feature set (and a published binary)

Test Plan

Ran the benchmarks for each project and verified the diagnostics I saw:

uv run benchmark -p black --mypy --verbose

I'm a bit surprised that I e.g. see an error for Black. I would appreciate it if someone could verify that the diagnostics are reasonable.

Comment on lines 25 to 26
INCREMENTAL = "incremental"
"""Incremental check between two commits."""
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we should remove this one again. I don't have an incremental benchmark yet but the idea would be to switch between two revisions.

@MichaReiser MichaReiser force-pushed the knot-mypy-pyright-benchmarks branch from 5694376 to 8da745b Compare August 21, 2024 09:12
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Aug 21, 2024
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Some comments from reading through the code

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Basically this all looks good to me in terms of structure, nothing sticks out

"--venvpath",
str(
venv.path.parent
), # This is not the path to the venv folder, but the folder that contains the venv...
Copy link
Member

Choose a reason for hiding this comment

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

wow, bizarre. Do we also need to specify --venv=venv along with this argument, so that it knows which subdirectory inside the --venv-path directory the venv is in? https://github.com/microsoft/pyright/blob/main/docs/import-resolution.md#configuring-your-python-environment

Copy link
Member Author

@MichaReiser MichaReiser Aug 22, 2024

Choose a reason for hiding this comment

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

Yes we do. But there's no venv CLI option. So we have to create a config

    for project in projects:
        with tempfile.TemporaryDirectory() as cwd:
            cwd = Path(cwd)
            project.clone(cwd)

            venv = Venv.create(cwd)
            venv.install(project.dependencies)

            # Set the `venv` config for pyright. Pyright only respects the `--venvpath`
            # CLI option when `venv` is set in the configuration... 🤷‍♂️
            with open(cwd / "pyrightconfig.json", "w") as f:
                f.write(json.dumps(dict(venv=venv.name)))

Copy link
Member

Choose a reason for hiding this comment

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

pyright's config setup is so odd...

@MichaReiser MichaReiser force-pushed the knot-mypy-pyright-benchmarks branch from 8da745b to 9ccaa8a Compare August 22, 2024 14:18
@MichaReiser MichaReiser force-pushed the knot-mypy-pyright-benchmarks branch from 9ccaa8a to ee2e088 Compare August 22, 2024 14:31
@MichaReiser MichaReiser marked this pull request as ready for review August 22, 2024 14:32
@MichaReiser MichaReiser merged commit 4f6accb into main Aug 23, 2024
@MichaReiser MichaReiser deleted the knot-mypy-pyright-benchmarks branch August 23, 2024 06:22
"pip",
"install",
"--quiet",
*dependencies,
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth adding --exclude-newer? While you pin the commit, you don't pin the deps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants