Skip to content
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

Highjack OPCODES to run other common instructions #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kstrauser
Copy link

DO NOT MERGE

This is just for demonstration purposes. In a nutshell, I kinda-profiled the instructions being called by putting print(inst) before the first if inst == Inst.... line, then running python test.py | sort | uniq -c | sort -n to see which ones were called most. That happened to be Inst.INVOKESTATIC and Inst.IINC.

I pulled each of those out into methods on Machine (so that they still have access to self), then injected them into the OPCODES dict so that they act like the other opcode functions. The main difference is that OPCODES[inst](frame) is calling a method instead of a module-level function, but sshhhh, that's our little secret.

This gave about a 10% speedup, as Python doesn't have to work its way through a big if ... elif ... elif block.

Even if you ❤️ this approach, please do it in a prettier way than I did. I just wanted to make it work, period, as an experiment. 🙂

Oh, also, I apologize for the whitespace changes. I've configured my editor to use Black on all my Python, and I'd forgotten to disable that before saving. GitHub has an option to ignore whitespace in its diffs so that should hide the Black stuff so you can see the actual code changes.

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.

1 participant