-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
optimizations #5
Comments
Hi, thanks for taking the time to create this issue! I realise I haven't written the goals for this project anywhere, so here they are:
Non-Goals:
The following suggestions I feel are out of scope, as the code can be minified by just writing better code:
I appreciate you can't always change the input code but it's a lot of effort to add these. Without doing a level of dynamic analysis which is difficult or impossible, it would only work for relatively trivial examples. For the following suggestions, I thought python-minifier already produced optimal code - have you got any examples where that's not the case?
These are good ideas! I think these can be in the next version:
This is a good idea, but more difficult:
|
edit: indentation at the way I did it becomes invisible so I added indent for indentation x = input() becomes: could be: And this: Remains the same but could be: Which is +4 bytes for import and -6 bytes for every print, and thus -18 is an improvement of 14 bytes For the literal that is only used once I can't find an example anymore but I have had it once. Kind regards |
Hi, thanks again for creating those examples! Bear in mind that after minification indents become tab characters, which are a single byte long - the same as spaces. I use tabs because the output is more readable. In your example we can eliminate the for loop entirely, but that's because we know there are no side effects to the In the decimal example I think you have rename-globals disabled, which prevents that transformation because it introduces the new name
|
Numbers greater than 10 ^ 45 get minified with hex, but would be shorter in base 36 (int(string, 36) will convert back to decimal) |
the one that shows conversion of 1000000000000 into 10**12 instead of 0xe8d4a51000 might not be a great idea considering the performance penelty of multiplying the number 12 times at runtime. this might even become a problem for performance requirements of some projects. How about make that optional. I have worked with that power operator and it is slow sometimes. |
Because both import dis
dis.dis("10 ** 12")
|
I understand that now, I believe I was still new to this field back then. Thanks for knowledge! |
a="Hello, how are you";print(a+"?");print(a+" now?")
The text was updated successfully, but these errors were encountered: