cache the md5 sum in Style/Supervisor.php and subclasses to make getHashCode cheaper #4426
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.
This pull request introduces a way to cache the md5 sum in Style/Supervisor.php and its subclasses to try and make getHashCode() less expensive to call.
This also introduces the necessity to call updateHashBeforeUse() on those classes when there is a change that affects the hash code to make the hash code update when needed.
Whether this is an acceptable trade-off will be decided by the maintainers.
I assume this is tested by the existing unit tests.
This is:
Checklist:
Why this change is needed?
The getHashCode function in PhpOffice\PhpSpreadsheet\Style\Supervisor and its subclasses is expensive. Conditional formatting causes new Styles to be created more than in other cases. Cacheing the md5sum of those classes and marking it to be updated upon a change makes the getHashCode function way less expensive.
Below are comparisons of execution times without and with this pull request. (the ep.xlsx contains a lot of conditional formatting (it also exits with a FormulaError)
The gain is ~15% for the conditional formatting- heavy xlsx->html and ~7.5% when all the unit tests are run.