KEMBAR78
gh-102839: remove AC for math.log by skirpichev · Pull Request #102863 · python/cpython · GitHub
Skip to content

Conversation

@skirpichev
Copy link
Contributor

@skirpichev skirpichev commented Mar 21, 2023

Before:

$ ./python -m timeit -s 'from math import log' 'log(1.1)' 1000000 loops, best of 5: 344 nsec per loop
$ ./python -m timeit -s 'from math import log' 'log(1.1, 3.2)' 500000 loops, best of 5: 601 nsec per loop

After:

$ ./python -m timeit -s 'from math import log' 'log(1.1)' 2000000 loops, best of 5: 171 nsec per loop
$ ./python -m timeit -s 'from math import log' 'log(1.1, 3.2)' 1000000 loops, best of 5: 348 nsec per loop

Before:
$  ./python -m timeit -s 'from math import log' 'log(1.1)'
1000000 loops, best of 5: 344 nsec per loop
$ ./python -m timeit -s 'from math import log' 'log(1.1, 3.2)'
500000 loops, best of 5: 601 nsec per loop

After:
$  ./python -m timeit -s 'from math import log' 'log(1.1)'
2000000 loops, best of 5: 171 nsec per loop
$ ./python -m timeit -s 'from math import log' 'log(1.1, 3.2)'
1000000 loops, best of 5: 348 nsec per loop
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
PyObject *base)
/*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
math_log(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment about why it is not converted to AC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I did.

skirpichev and others added 2 commits March 21, 2023 14:00
@skirpichev skirpichev requested a review from sobolevn March 21, 2023 11:12
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is what we have to go.
See: faster-cpython/ideas#565

@rhettinger
Copy link
Contributor

If and when the AC gets improved, we can convert this back to AC. In the meantime, let's take the performance win. We will see immediate benefits in some of the random module distribution calculations.

@rhettinger
Copy link
Contributor

@skirpichev My timings are about 7x faster than yours. Are you using a debug build for timings, a non-representative machine, or an older compiler?

@rhettinger
Copy link
Contributor

@mdickinson Are you on board with this?

@mdickinson
Copy link
Member

@rhettinger Yep, fine by me. Looks like a significant performance boost.

@skirpichev
Copy link
Contributor Author

If and when the AC gets improved, we can convert this back to AC. In the meantime, let's take the performance win.

In fact, it's possible to keep AC stuff, if we "corrupt" it like cmath.log:

/*[clinic input]
math.log

    x:    object
    base: object = NULL
    /

log(x[, base=math.e]) -> the logarithm of x to the given base.

If the base not specified, returns the natural logarithm (base e) of x.
[clinic start generated code]*/

at cost of slight change in the docstring. Not sure it worth, this just hide the problem with AC/inspect capabilities.

My timings are about 7x faster than yours. Are you using a debug build for timings, a non-representative machine, or an older compiler?

@rhettinger, perhaps, the second option. This was a usual (./confiqure -q && make -s) build with gcc Debian(bullseye) 10.2.1-6.

@rhettinger rhettinger merged commit d1a89ce into python:main Mar 21, 2023
@skirpichev skirpichev deleted the 102839-math.log-noAC branch March 22, 2023 00:11
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants