Cache Lattice
property (lengths/angles/volume
) for much faster Structure.as_dict
#4421
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
lengths/angles/volume
ofLattice
would now be cached, related toorjson
for much faster JSON operations? #4385verbosity
inas_dict
ofPeriodicSite/Lattice
now explicitly requires literal 0 or 1 to be consistent with docstring, instead of checkingif verbosity > 0
(currently in grace period, only warning issued)pymatgen/src/pymatgen/core/lattice.py
Lines 904 to 905 in 34608d0
Cache frequently used
Lattice
propertiesCurrently
length/angles/volume
is not cached and is frequently used, for example accessing all lattice parameter related property would lead tolength/angles
being repeatedly calculated:pymatgen/src/pymatgen/core/lattice.py
Lines 475 to 524 in 34608d0
structure.as_dict
now around 8x fasterBefore (1000 structure, each has 10-100 atoms):
Now:
Also note
lattice
(the performance bottleneck) is not used in the dict for site:pymatgen/src/pymatgen/core/structure.py
Lines 2856 to 2857 in 34608d0
So we could modify
as_dict
to control whether lattice would be generated at allThis could reduce the runtime slightly so I guess it's not worth the effort: