This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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: methane, tim.peters
Priority: normal Keywords: patch

Created on 2019-07-10 10:59 by methane, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14674 merged methane, 2019-07-10 11:28
PR 15309 hansrajdas, 2019-08-18 10:11
Messages (2)
msg347615 - (view) Author: Inada Naoki (methane) * (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 (methane) * (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
2022-04-11 14:59:17adminsetgithub: 81724
2019-08-18 10:11:20hansrajdassetpull_requests: + pull_request15043
2019-07-17 12:24:34methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-07-17 12:24:04methanesetmessages: + msg348057
2019-07-10 14:45:37tim.peterssetnosy: + tim.peters
2019-07-10 11:28:35methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request14489
2019-07-10 10:59:54methanecreate