Commit a3c7ed6
committed
Improve speed of
Replace `_path` (which constructs the path including AoS indices) with the static `metadata.path_string` when an attribute cannot be found.
Speeds up the following sample from 110ms to 0.5ms (200x gain):
```python
import timeit
import imas
cp = imas.IDSFactory().core_profiles()
cp.profiles_1d.resize(1000)
def totime():
hasattr(cp.profiles_1d[999], "xyz")
print(timeit.repeat(totime, number=1000))
```
**Changed behaviour:**
Before: `AttributeError: IDS structure 'profiles_1d[999]' has no attribute 'xyz'`
After: `AttributeError: IDS structure 'profiles_1d' has no attribute 'xyz'`
Since the index of an AoS is not relevant for whether an attribute exists or not, I believe this is not a problem.hasattr on IDS structures1 parent a4f5a4b commit a3c7ed6
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
0 commit comments