Skip to content

Comments

Remove unnecessary and costly calls to typing.get_type_hints#274

Merged
cbourjau merged 1 commit intomainfrom
reduce-calls-to-get_type_hints
Feb 17, 2026
Merged

Remove unnecessary and costly calls to typing.get_type_hints#274
cbourjau merged 1 commit intomainfrom
reduce-calls-to-get_type_hints

Conversation

@cbourjau
Copy link
Collaborator

Profiling the construction of fairly large graphs by @SamuelLessmannQC found that we spend a considerable fraction of the run time in typing.get_type_hints. This PR refactors the code in a minimally invasive way to remove unnecessary calls to that function.

On a larger picture, I'd like to refactor this code for a very long time, but that is on an equally low priority. As it stands right now, each Node has an associated Inputs and Outputs type. The machinery around those is fairly complex, but ultimately performs only some simple validations. Alas, things work splendidly, so I don't think this is the day to make a larger refactor.

Checklist

  • Added a CHANGELOG.rst entry

Comment on lines -99 to -100
# Cast to tuple to avoid accidental mutation
setattr(self, field.name, tuple(value))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal prompted me to update the type hints in this PR.

@SamuelLessmannQC
Copy link

On a ~3600 node model, this change reduces build time from 2:50 to 2:16 (~20%)! 🚀

@cbourjau cbourjau merged commit 929e7f8 into main Feb 17, 2026
15 checks passed
@cbourjau cbourjau deleted the reduce-calls-to-get_type_hints branch February 17, 2026 15:56
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.

2 participants