enthought / enthought/traits

Extend use of static notifications due to high memory consumption of dynamic ones

Open
#258 0 comments 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

#### General description

Dynamic notifications have an extraordinarily high memory consumption. Only a very limited number of cases (the item itself, items of List traits and Dict traits) are covered by notifications via the special naming convention, which generate static notifications.

For items of a List trait foo a static notification would be

```
def _foo_items_changed():
pass
```

while a dynamic case would be

```
@on_trait_change('foo[]') # this also includes the item itself
def bar(self):
pass
```

For items of an Array trait foo, however, the dynamic syntax still works, while the static does not. This excludes even items of numpy arrays from having static notifications.
#### My suggestion

I really would like to use _foo_items_changed() for (numpy) - Arrays. In general however i suggest to make use of static notifications possible wherever the implementation is feasible.

EDIT: I just realized, that the @on_trait_change decorator is the cause for quite a few tickets opened in this issue tracker.
#### Some numbers from my use case

I use the @on_trait_change decorator six times in my code and i build around 200 instances of that class. Replacing the decorator with the special method naming convention reduces the memory consumption of my program from 36MB to 8MB. With the same functionality. However now i have to use List() instead of an Array() (it is a 1D numpy array), which is inacceptable in my case.
#### Related Issues

https://github.com/enthought/traits/issues/255
https://github.com/enthought/traits/issues/256

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.