Skip to content

Conversation

@graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Jan 15, 2026

This PR changes math.fsum() to use the port of XSum also used in GraalJS. The speedup on a microbenchmark is significant both with compilation enabled and in interpreter-only mode:

# GraalPy without XSum (with compilation)
$ graalpy bench_fsum.py
Sum of 100 numbers: 0.021997 seconds
Sum of 1000 numbers: 0.005800 seconds
Sum of 10000 numbers: 0.054701 seconds
Sum of 100000 numbers: 0.517120 seconds
Sum of 1000000 numbers: 4.981345 seconds

# GraalPy with XSum (with compilation)
$ graalpy bench_fsum.py
Sum of 100 numbers: 0.025060 seconds
Sum of 1000 numbers: 0.007285 seconds
Sum of 10000 numbers: 0.026717 seconds
Sum of 100000 numbers: 0.140376 seconds
Sum of 1000000 numbers: 1.381729 seconds

# GraalPy without XSum (interpreter only)
$ graalpy bench_fsum.py
Sum of 100 numbers: 0.009417 seconds
Sum of 1000 numbers: 0.027649 seconds
Sum of 10000 numbers: 0.166529 seconds
Sum of 100000 numbers: 1.514038 seconds
Sum of 1000000 numbers: 14.632675 seconds

# GraalPy with XSum (interpreter only)
$ graalpy bench_fsum.py
Sum of 100 numbers: 0.007540 seconds
Sum of 1000 numbers: 0.024484 seconds
Sum of 10000 numbers: 0.101314 seconds
Sum of 100000 numbers: 0.809227 seconds
Sum of 1000000 numbers: 7.568794 seconds

# CPython
$ python3.11 bench_fsum.py
Sum of 100 numbers: 0.001679 seconds
Sum of 1000 numbers: 0.015773 seconds
Sum of 10000 numbers: 0.126783 seconds
Sum of 100000 numbers: 1.238006 seconds
Sum of 1000000 numbers: 12.508949 seconds

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants