New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preparse old-style octals as strings #17808
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch: u/jdemeyer/ticket/17808 |
Commit: |
Author: Jeroen Demeyer |
New commits:
|
comment:5
I would think the slow-down for small integers makes the proposed changes very unattractive. The whole idea of preparsing For instance, in code like:
you really start to notice this. preparse_file mitigates issues like this a little bit by factoring out numeric constants, so that their conversion doesn't happen in inner loops. If you want to store your numerical constants as strings in the byte code and have fast conversion, you should probably store them in hex. It's a little more work in the preparser, but the result is more compact and conversion to a numerical constant is truly linear in number of bits. |
comment:6
Replying to @nbruin:
Is that really important? The "timeit" example is of course a bit artificial. |
comment:7
Replying to @jdemeyer:
I think so. Storing the numerical constant as a string forces the decimal-to-binary conversion to happen at runtime. If you just write it as a python integer, the conversion happens at parsing, so by the time it's an ast and the compiler looks at it, you're already dealing with an integer. Unfortunately, python doesn't permit compile-time macros (perhaps if we're ever going to rewrite our preparser to properly parse, we can combine it with MacroPy and then we can have I am fairly certain that nearly all code that gets run with sage has TONS of small integer literals in it. Probably for many applications, people would get better performance writing If you use |
comment:8
Fine, you convinced me. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Changed branch from u/jdemeyer/ticket/17808 to public/ticket/17808 |
comment:17
is the title still acurately describing the content of the ticket ? |
comment:18
Replying to @fchapoton:
Yes. |
This comment has been minimized.
This comment has been minimized.
comment:19
Although the ticket does change a little bit more than that, I added a sentence to the description. |
This comment has been minimized.
This comment has been minimized.
Reviewer: Frédéric Chapoton |
comment:21
ok, looks good to me |
Changed branch from public/ticket/17808 to |
To solve #17807, we preparse
0100
asInteger('0100')
instead ofInteger(0100)
: thanks to #17413, this will give a deprecation warning so that users should know something funny is going on:We also preparse new-style binary/octal/hex strings as integers instead of strings, which should be faster, see [comment:5].
Component: python3
Author: Jeroen Demeyer
Branch/Commit:
52fd0ce
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/17808
The text was updated successfully, but these errors were encountered: