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

Do not create code objects #869

Merged
merged 3 commits into from Jul 19, 2018

Conversation

Projects
None yet
2 participants
@patiences
Copy link
Contributor

commented Jul 16, 2018

This change is about not creating Code objects, only grabbing the values that are needed. This reduces the overhead of creating functions (so it is a one-time gain per function). Let's see some performance stats:

On benchmarking test:
Without optimization

Running test_code
  Elapsed time:  69.84982615604531  sec
  CPU process time:  0.0008669999999999511  sec
Running test_code
  Elapsed time:  69.89342098298948  sec
  CPU process time:  0.0009319999999999329  sec
Running test_code
  Elapsed time:  68.42389843205456  sec
  CPU process time:  0.0009710000000000552  sec
Running test_code
  Elapsed time:  69.35569038696121  sec
  CPU process time:  0.0010740000000000194  sec

With optimization

Running test_code
  Elapsed time:  51.62230951199308  sec
  CPU process time:  0.0008390000000000342  sec
Running test_code
  Elapsed time:  52.12950277002528  sec
  CPU process time:  0.0010590000000000321  sec
Running test_code
  Elapsed time:  52.203202828997746  sec
  CPU process time:  0.0009040000000000159  sec
Running test_code
  Elapsed time:  52.396196495043114  sec
  CPU process time:  0.0010430000000000161  sec

About a 25% improvement.

On pystone:

Without optimization

test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 38.7340
This machine benchmarks at 1290.85 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 38.2483
This machine benchmarks at 1307.25 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 40.6756
This machine benchmarks at 1229.24 pystones/second

With optimization

test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 35.3792
This machine benchmarks at 1413.26 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 35.2154
This machine benchmarks at 1419.83 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 36.0494
This machine benchmarks at 1386.99 pystones/second

About a 8-ish% improvement.

patiences added some commits Jul 16, 2018

@patiences patiences changed the title [WIP] do not create code objects Do not create code objects Jul 19, 2018

if func.__code__ is not None:
print("Code object exists")
""")

This comment has been minimized.

Copy link
@patiences

patiences Jul 19, 2018

Author Contributor

This test shows what currently passes in master. If you try to access an attr like co_name, you get a Runtime Error: Illegal access to native field. So the __code__ attr exists, but the repr as well is not exactly correct, hence why it's not being tested here.

print("__code__:", func.__code__)
print("Function name:", func.__code__.co_name)
print("Arg count:", func.__code__.co_argcount)
""")

This comment has been minimized.

Copy link
@patiences

patiences Jul 19, 2018

Author Contributor

This test is I think the minimum of what should work when __code__ introspection is implemented (but does not currently work).

@freakboy3742
Copy link
Member

left a comment

👍

@freakboy3742 freakboy3742 merged commit 92aa7d6 into beeware:master Jul 19, 2018

5 checks passed

beekeeper:0/beefore:javacheckstyle Java lint checks passed.
Details
beekeeper:0/beefore:pycodestyle Python lint checks passed.
Details
beekeeper:1/smoke-test Smoke build (Python 3.4) passed.
Details
beekeeper:2/full-test:py3.5 Python 3.5 tests passed.
Details
beekeeper:2/full-test:py3.6 Python 3.6 tests passed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.