Perf: Remove unnecessary deepcopy
calls in Schemaview.induced_slot
#296
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up on linkml/linkml#1604
This is one of the largest sources of slow performance in the non-graph-based generators.
Currently, when I run the test suite, it takes me 50 minutes, which is entirely too long imo - we want tested contributions, but if i have to wait 50 minutes before submitting a PR or between every change then the odds start to really climb that i'm just going to forget about it.
This gets us down to 40 minutes essentially for free (and when using pydanticgen makes a ~60s generation process into ~2-3s).
First: we can remove the
deepcopy
at the end - that's wholly unnecessary, sinceinduced_slot
is already deepcopied earlier in the method. we don't need to protect something that will die immediately when the method ends.Second, we also don't need the deepcopy in the middle of the method:
get_slot
is cached.all_slots
which is also cached.all_slots
makes a (shallow) copy ofself._get_dict
as wellget_slot
doesn't find anything inall_slots
it makes a shallow copy of the class attributeso we shouldn't need
deepcopy
ininduced_slot
since the thing we draw from should be cached and copied already - future calls toget_slot
should get the cached copy even if we mutate it downstream. I replaced it with a regular copy since that's much faster if it's necessary at all.Third: Avoid double-calling
get_slot
with differing call signature since the first call is only necessary if we take the first leg of theif cls
statement.Fourth: the output of
induced_slot
is also cached, but it still seems like we're getting cache misses from the difference between slot name as a str vsSlotDefinitionName
. not fixed in this PR.Cumulative time in
Schemaview.induced_slot
before: 510s (95832 calls)Cumulative time in
Schemaview.induced_slot
after: 243s