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

ENH: optimize import time #199

Merged
merged 2 commits into from Jul 11, 2022
Merged

Conversation

neutrinoceros
Copy link
Member

@neutrinoceros neutrinoceros commented Aug 17, 2021

This is an answer to #27. I shave off about 33% of unyt's import time by making Unit objects copies shallow by default, the one difference with a deep copy being that the attached UnitRegistry is shallow-copied.

Using the benchmark I described in #27, I get the import time from 1.6s to 1.0s on my machine.
I hope that this doesn't have undesirable side effects.
Another aspect that could be considered is that the sheer number of copies that are performed at import time is probably a sign that something else isn't optimized.

@ngoldbaum
Copy link
Member

One way to check if this has real impacts on a codebase that depends on unyt is to run the yt unit tests and look for new failures. I can think of cases where shallow copying the unit registry dict could affect runtime behavior, particularly in situations where there’s more than one unit registry to worry about. yt exercises those cases much more than the unyt tests.

@neutrinoceros
Copy link
Member Author

Good call, thank you !

@neutrinoceros
Copy link
Member Author

I've run yt's test suite against this branch and everything stayed green !

@neutrinoceros
Copy link
Member Author

On my other machine the import time goes from 2.4s to 1.8s. Still about 25% gain. about 50% of the remaining import time is from unyt itself so I expect there is still room for future optimisations.

@jzuhone
Copy link
Contributor

jzuhone commented Jun 21, 2022

@neutrinoceros please rebase this and perform the same check on the yt codebase that Nathan suggested earlier again, since it's been so long.

@neutrinoceros
Copy link
Member Author

Just did. Still no error to report !

@jzuhone
Copy link
Contributor

jzuhone commented Jun 21, 2022

@matthewturk could you double-check this one?

@jzuhone
Copy link
Contributor

jzuhone commented Jul 10, 2022

@neutrinoceros please fix this one, we'll get it in for 2.9

@neutrinoceros
Copy link
Member Author

Sure ! I can do that in a few hours, when I'm home.

@neutrinoceros
Copy link
Member Author

@jzuhone done

@jzuhone
Copy link
Contributor

jzuhone commented Jul 11, 2022

@matthewturk Could you have a quick look at this?

@neutrinoceros
Copy link
Member Author

FWIW I'm working on automating the process of checkin compatibility with unyt's dev branch on yt's side here yt-project/yt#4007

@matthewturk
Copy link
Member

This looks OK to me. I think that one of the things we should look at is how the change in turning off deep-copy-by-default affects performance -- a while back I remember looking at things like covering grids etc in yt and finding that much of the time was spent in copying and creating the affiliated objects (like the various Printer subclasses in sympy).

@neutrinoceros
Copy link
Member Author

So, would a simple benchmark using yt's covering grid do ?

@matthewturk
Copy link
Member

@neutrinoceros We do not need to run one. I was noting it because I want to run one after thigns have settled down.

@neutrinoceros
Copy link
Member Author

So are we go on this ?

@jzuhone jzuhone merged commit 51e28d8 into yt-project:master Jul 11, 2022
@neutrinoceros neutrinoceros deleted the opti_import_time branch July 11, 2022 18:59
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.

None yet

4 participants