Skip to content
This repository has been archived by the owner. It is now read-only.

Do not create code objects #869

Merged
merged 3 commits into from Jul 19, 2018
Merged

Do not create code objects #869

merged 3 commits into from Jul 19, 2018

Conversation

@patiences
Copy link
Contributor

@patiences patiences 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 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")
""")
Copy link
Contributor Author

@patiences patiences Jul 19, 2018

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)
""")
Copy link
Contributor Author

@patiences patiences Jul 19, 2018

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

Copy link
Member

@freakboy3742 freakboy3742 left a comment

👍

@freakboy3742 freakboy3742 merged commit 92aa7d6 into beeware:master Jul 19, 2018
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants