[New-bugs-announce] [issue38252] micro-optimize ucs1lib_find_max_char in Windows 64-bit build

Ma Lin report at bugs.python.org
Sun Sep 22 07:50:02 EDT 2019

New submission from Ma Lin <malincns at 163.com>:

C type `long` is 4-byte integer in 64-bit Windows build. [1]

But `ucs1lib_find_max_char()` function [2] uses SIZEOF_LONG, so it loses a little performance in 64-bit Windows build.

Below is the benchmark of using SIZEOF_SIZE_T and this change:

    -   unsigned long value = *(unsigned long *) _p;
    +   sizt_t value = *(sizt_t *) _p;

D:\dev\cpython\PCbuild\amd64\python.exe -m pyperf timeit -s "b=b'a'*10_000_000; f=b.decode;" "f('latin1')"

    before: 5.83 ms +- 0.05 ms
    after : 5.58 ms +- 0.06 ms

[1] https://stackoverflow.com/questions/384502

[2] https://github.com/python/cpython/blob/v3.8.0b4/Objects/stringlib/find_max_char.h#L9

Maybe there can be more optimizations, so I didn't prepare a PR for this.

components: Interpreter Core
messages: 352970
nosy: Ma Lin, inada.naoki, serhiy.storchaka, sir-sigurd
priority: normal
severity: normal
status: open
title: micro-optimize ucs1lib_find_max_char in Windows 64-bit build
type: performance
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list