Issue 1511853: Speed up decimal object construction (original) (raw)

The numerical programming discussion on python-dev reminded me to try out the new profiler on the decimal module.

It showed more than a quarter of the execution time for the unit tests was being spent in decimal.new and in doing isinstance checks.

This patch adds fast paths that avoids the isinstance checks when dealing solely with builtin types. It also caches a couple of incidental values when checking for special Decimal values during construction from a string instead of making the same function calls twice.

However, while the speed benefit was significant under profiling (saving around 15 seconds on the 60 second runtime of the decimal unit tests), it was far less impressive under normal operation (saving around 0.5 seconds on the 12.5 second run time of the unit tests, and around 5 seconds on the 530+ seconds needed to run the full telco.py benchmark).

So it's definitely faster, but the real magnitude of the benefit is still an open question.