Skip to content

Fix benchmarks by replacing rust-cpython with pyo3#5163

Merged
youknowone merged 2 commits intoRustPython:mainfrom
dchiquito:fix-benches
Feb 10, 2024
Merged

Fix benchmarks by replacing rust-cpython with pyo3#5163
youknowone merged 2 commits intoRustPython:mainfrom
dchiquito:fix-benches

Conversation

@dchiquito
Copy link
Contributor

The benchmarks seem to have been broken since Python 3.10 deprecated the API
they were using to parse and execute CPython baselines. Since then
rust-cpython has been deprecated in favor of pyo3.

  • Replace cpython and python3-sys dependencies with pyo3.
  • Add html_report feature to criterion, it will be required in a
    future release.
  • Remove anyhow. It was unused and cargo cleaned it up automatically.
  • Use compile and exec from within the CPython context to
    compile and execute benchmarks. There's probably more overhead to that than
    the internal API had, but that overhead should be consistent per
    benchmark.

If anyone cares about hyperoptimizing benchmarks then they can optimize
the harness as well.

Fixes #3498

The benchmarks have been broken since Python 3.10 deprecated the API
they were using to parse and execute CPython baselines. Since then
rust-cpython has been deprecated in favor of pyo3.

- Replace `cpython` and `python3-sys` with `pyo3`.
- Add `html_report` feature to `criterion`, it will be required in a
  future release.
- Remove `anyhow`. It was unused and cargo cleaned it up automatically.
Update the actual benchmark harnesses.

Because the internal APIs previously used are no longer available, I
opted to use `compile` and `exec` from within the CPython context to
compile and execute code. There's probably more overhead to that than
the internal API had, but that overhead should be consistent per
benchmark.

If anyone cares about hyperoptimizing benchmarks then they can optimize
the harness as well.
@fanninpm
Copy link
Contributor

fanninpm commented Feb 9, 2024

Use compile and exec from within the CPython context to
compile and execute benchmarks. There's probably more overhead to that than the internal API had, but that overhead should be consistent per benchmark.

I have a minor question: How do we know that this won't inadvertently give RustPython an advantage? As far as I know, the API we used (from before CPython 3.10) ensured that compilation was kept separate from execution.

@fanninpm
Copy link
Contributor

fanninpm commented Feb 9, 2024

Also, if I recall correctly, the RustPython benchmarks will eat up a lot of memory because RustPython presently has no garbage collection more advanced than simple reference-counting and needs circular references in order to set up simple things like object and type. (See also #2380.)

@dchiquito
Copy link
Contributor Author

When I originally tried to run the benchmarks they just failed to build because of features deprecated in Python 3.10, so my understanding was that they just haven't worked since the project moved past that point. My objective with this PR was to get something working so that I could benchmark some changes I was making.

From my cursory investigation, I couldn't find that pyo3 exposed a similar API to what was there previously. I think the difference between calling the CPython exec and hooking into whatever function it uses internally is small enough for now. If maintaining parity is important I can dig deeper.

I'm bummed about garbage collection too, but I don't see that it should block improving the benchmarking code.

@fanninpm
Copy link
Contributor

The reason I warned about GC is so that you're not surprised if the benchmarks crash due to your system not having enough RAM. (From what I recall, RustPython chews through about 16 GB of RAM.)

@dchiquito
Copy link
Contributor Author

Thanks for the warning! That is probably why I crashed my computer a few times testing this PR lol

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Thank you! it was broken for years and finally going to be fixed

@youknowone youknowone merged commit 1005577 into RustPython:main Feb 10, 2024
@dchiquito dchiquito deleted the fix-benches branch February 10, 2024 02:51
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.

Benchmarks use PyParser_ASTFromStringObject, which is removed from Python 3.10

3 participants