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

Performance: decrease runtime overhead for constructing HasTraits (up to 20x faster) #777

Merged
merged 21 commits into from
Dec 8, 2022
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4dbcd53
perf: find default generators at class contruction time
maartenbreddels Sep 14, 2022
a9a434b
perf: find descriptors at class construction time
maartenbreddels Sep 14, 2022
7114fed
perf: only add notifiers when they exist
maartenbreddels Sep 14, 2022
96dd844
perf: avoid cross_validation_lock context manager
maartenbreddels Sep 14, 2022
e6d4159
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2022
3890f72
perf: get app traits during class construction instead of runtime
maartenbreddels Sep 14, 2022
304e888
typing
maartenbreddels Sep 14, 2022
5dd9d70
perf: avoid dynamic default code path for static immutable defaults
maartenbreddels Sep 26, 2022
a72261d
typing
maartenbreddels Sep 26, 2022
a7c22ca
perf: avoid unnecessary dict presence checks
maartenbreddels Sep 26, 2022
05d3023
more trivial immutable static initial values
maartenbreddels Sep 28, 2022
aff9d0c
perf: better scaling due to skipping instance_init when possible.
maartenbreddels Sep 28, 2022
d0ec5ff
perf: specialized version of hold_trait_notifications in ctor
maartenbreddels Sep 28, 2022
bf33e88
perf: skip setup if no kwargs are given
maartenbreddels Sep 28, 2022
8e04ed9
fix: validate return value should be used
maartenbreddels Sep 28, 2022
5bb5924
flake8: unused variable
maartenbreddels Sep 28, 2022
09ca954
perf: opt out instance_init for bool and enum
maartenbreddels Sep 29, 2022
1c85d41
perf: all instances that are None are immutable and static
maartenbreddels Sep 29, 2022
dae860f
perf: remove usage of named attribute accesses on bunches
naterush Oct 21, 2022
1cc97d4
trigger ci
maartenbreddels Dec 8, 2022
36fdaf5
trigger ci
maartenbreddels Dec 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
typing
  • Loading branch information
maartenbreddels committed Dec 8, 2022
commit 304e8885b229d72590097df91469f048fc812515
6 changes: 4 additions & 2 deletions traitlets/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def setup_class(cls, classdict): # noqa
cls._all_trait_default_generators[name] = c.__dict__[default_method_name]
break
if name in c.__dict__.get("_trait_default_generators", {}):
cls._all_trait_default_generators[name] = c._trait_default_generators[name]
cls._all_trait_default_generators[name] = c._trait_default_generators[name] # type: ignore[attr-defined]
break
else:
cls._all_trait_default_generators[name] = trait.default
Expand Down Expand Up @@ -1238,6 +1238,8 @@ class HasTraits(HasDescriptors, metaclass=MetaHasTraits):
_trait_notifiers: t.Dict[str, t.Any]
_trait_validators: t.Dict[str, t.Any]
_cross_validation_lock: bool
_traits: t.Dict[str, t.Any]
_all_trait_default_generators: t.Dict[str, t.Any]

def setup_instance(*args, **kwargs):
# Pass self as args[0] to allow "self" as keyword argument
Expand Down Expand Up @@ -1423,7 +1425,7 @@ def _notify_observers(self, event):
if name in self._trait_notifiers:
callables.extend(self._trait_notifiers.get(name, {}).get(type, []))
callables.extend(self._trait_notifiers.get(name, {}).get(All, []))
if All in self._trait_notifiers:
if All in self._trait_notifiers: # type:ignore[comparison-overlap]
callables.extend(
self._trait_notifiers.get(All, {}).get(type, []) # type:ignore[call-overload]
)
Expand Down