classification
Title: Optimize pymalloc for non PGO build
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, tim.peters
Priority: normal Keywords: patch

Created on 2019-07-10 10:59 by inada.naoki, last changed 2019-07-17 12:24 by inada.naoki. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14674 merged inada.naoki, 2019-07-10 11:28
Messages (2)
msg347615 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-07-10 10:59
When PGO is not used, compilers don't know which part is hot.

So gcc failed to inline hot code in pymalloc_alloc and pymalloc_free
into _PyObject_Malloc and _PyObject_Free.  For example, only this code is inlined into _PyObject_Malloc.

    if (nbytes == 0) {
        return 0;
    }
    if (nbytes > SMALL_REQUEST_THRESHOLD) {
        return 0;
    }

But the hottest part is taking memory block from freelist in the pool.
To optimize it,

* make pymalloc_alloc and pymalloc_free inline functions
* Split code for rare / slow paths out to new functions

In PR 14674, pymalloc is now as fast as mimalloc in spectral_norm benchmark.

  $ ./python bm_spectral_norm.py --compare-to=./python-master
  python-master: ..................... 199 ms +- 1 ms
  python: ..................... 176 ms +- 1 ms

  Mean +- std dev: [python-master] 199 ms +- 1 ms -> [python] 176 ms +- 1 ms: 1.13x faster (-11%)
msg348057 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-07-17 12:24
New changeset fb26504d14a08fcd61bb92bb989b6d2b12188535 by Inada Naoki in branch 'master':
bpo-37543: optimize pymalloc (#14674)
https://github.com/python/cpython/commit/fb26504d14a08fcd61bb92bb989b6d2b12188535
History
Date User Action Args
2019-07-17 12:24:34inada.naokisetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-07-17 12:24:04inada.naokisetmessages: + msg348057
2019-07-10 14:45:37tim.peterssetnosy: + tim.peters
2019-07-10 11:28:35inada.naokisetkeywords: + patch
stage: patch review
pull_requests: + pull_request14489
2019-07-10 10:59:54inada.naokicreate