Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

copy.deepcopy() takes 55% of runtime of a simple benchmark #160

Closed
grigi opened this issue Sep 25, 2018 · 3 comments
Closed

copy.deepcopy() takes 55% of runtime of a simple benchmark #160

grigi opened this issue Sep 25, 2018 · 3 comments

Comments

@grigi
Copy link
Contributor

grigi commented Sep 25, 2018

Hi, we are working on Tortoise ORM and I did a series of simple benchmarks to start finding performance bottlenecks. In the one transactioned insert test:
https://github.com/tortoise/orm-benchmarks#interesting-profiling-results
I found that copy.deepcopy() takes ~55% of the runtime. Changing it to copy.copy() gives me an 83% speed up in that particular test.

Of course it is there for a reason as without it we can get unexpected side-effects, such as what the pypika.tests.test_joins.JoinBehaviorTests.test_immutable__queries_after_join test determines.

I'm just wondering what can we do to speed this up?

@twheys
Copy link
Contributor

twheys commented Sep 26, 2018

Deepcopy could be replaced with a more comprehensive implementation of __copy__ in the QueryBuilder class. Can you try using the changes in my PR #161 in your benchmark and let me know if you see a similar improvement?

@grigi
Copy link
Contributor Author

grigi commented Sep 26, 2018

Thanks @twheys
I did the test and got a 53% speedup in that particular benchmark.
Thank you, this is a big gain 👍

@twheys
Copy link
Contributor

twheys commented Sep 26, 2018

Is that sufficient? Could probably try and optimize a bit better. The copies are used to keep the queries immutable.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants