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

Defer Style initialization to when it is needed #586

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

Alexboiboi
Copy link
Member

Notes

When working on some routine code where the creation of magpylib objects is very frequent, specifying style attributes cost some significant additional initialization time, so we tend to avoid using them in these cases. However it is quite convenient to be able to give at least a style.label to our objects in order to track them more easily later.

This PR partly addresses this issue by deferring the style class tree initialization to when it is really called explicitly (e.g. obj.style...). It allows to declare some style_kwargs at init level without carrying the time penalty right away. This would be even more relevant if we decide to implement #397.
Here some before/after examples to illustrate the use cases:

image

@Alexboiboi
Copy link
Member Author

@OrtnerMichael Please merge this, reviewing should only take a couple of minutes! Thx

Copy link
Member

@OrtnerMichael OrtnerMichael left a comment

Choose a reason for hiding this comment

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

makes a lot of sense to me

@OrtnerMichael OrtnerMichael merged commit 59b71f0 into main Feb 16, 2023
@OrtnerMichael OrtnerMichael deleted the optimize-style-kwargs-init branch February 16, 2023 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants