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

Slight performance improvements for Dir::inventory() #6218

Merged
merged 22 commits into from
Feb 23, 2024

Conversation

distantnative
Copy link
Member

@distantnative distantnative commented Jan 28, 2024

This PR …

Tried to fix #5126 - while the issue itself remains without a good solution, some improvements to the methods structure and performance could be made. Added those in this PR.

Refactored

  • Slight performance improvements for Dir::inventory()

Housekeeping

  • Upgraded Psalm
  • Added performance tests for Dir::inventory() with various number of page models

Ready?

  • Unit tests for fixed bug/feature
  • In-code documentation (wherever needed)
  • Tests and checks all pass

For review team

  • Add changes to release notes draft in Notion

@distantnative distantnative added type: refactoring ♻️ Is about bad code; cleans up code type: performance ⚡️ Is about performance; improves performance labels Jan 28, 2024
@distantnative distantnative added this to the 4.2.0 milestone Jan 28, 2024
@distantnative distantnative self-assigned this Jan 28, 2024
@distantnative distantnative requested a review from a team January 28, 2024 11:26
@distantnative distantnative force-pushed the fix/5126-dir-inventory-performance branch from 6843143 to 9e36dec Compare January 30, 2024 16:42
@bastianallgeier
Copy link
Member

Are there any before/after numbers to compare this or is there a good way for me to compare locally?

@distantnative distantnative force-pushed the fix/5126-dir-inventory-performance branch from 8e92a46 to 7d97311 Compare February 3, 2024 20:15
@distantnative
Copy link
Member Author

@bastianallgeier

To run it yourself, you need to copy the added performance tests from bench/Filesystem over to the develop/minor state. There run composer run-script bench:baseline. Then you can switch back to the branch and run composer run-script bench. That way, performance of develop/minor is compared against this PR.

However, for me the result seems to be worse now after 7d97311

@bastianallgeier
Copy link
Member

That's so weird. Do you have any idea why this could perform worse?

@distantnative distantnative added needs: replication 🔬 Requires a sample to reproduce the issue needs: tests 🧪 Requires missing tests labels Feb 6, 2024
@distantnative distantnative force-pushed the fix/5126-dir-inventory-performance branch from 7d97311 to c903e6b Compare February 17, 2024 22:53
@distantnative distantnative removed the needs: replication 🔬 Requires a sample to reproduce the issue label Feb 17, 2024
@distantnative
Copy link
Member Author

@bastianallgeier I have reverted c903e6b again.

With it, the performance was worse than develop-minor, particularly with no or one model:
Screenshot 2024-02-17 at 23 53 54

After reverting that change, this PR shows slight improvements over develop-minor:
Screenshot 2024-02-17 at 23 53 46

My guess would be that for multilang installations, the difference isn't bad. But in the bench tests with single lang, calling the app instance even with $multilang = false adds quite some overhead.

@distantnative distantnative removed the needs: tests 🧪 Requires missing tests label Feb 17, 2024
@lukasbestle
Copy link
Member

My guess would be that for multilang installations, the difference isn't bad. But in the bench tests with single lang, calling the app instance even with $multilang = false adds quite some overhead.

Can't we also use if ($multilang === true) when fetching the language code? If it's false, we don't even need to load the app object. $languageCode can just always be null then.

Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the refactoring. Besides performance, the new structure makes much more sense and is easier to read and understand IMO.

src/Filesystem/Dir.php Outdated Show resolved Hide resolved
src/Filesystem/Dir.php Outdated Show resolved Hide resolved
@distantnative
Copy link
Member Author

Can't we also use if ($multilang === true) when fetching the language code? If it's false, we don't even need to load the app object. $languageCode can just always be null then.

I think it could still have performance downsides for multilang inventories without children (currently app instance wouldn't be called then at all, after the change it would be called).

distantnative and others added 2 commits February 23, 2024 21:47
Co-authored-by: Lukas Bestle <lukas@getkirby.com>
@distantnative distantnative merged commit 5f43dc2 into develop-minor Feb 23, 2024
12 checks passed
@distantnative distantnative deleted the fix/5126-dir-inventory-performance branch February 23, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: performance ⚡️ Is about performance; improves performance type: refactoring ♻️ Is about bad code; cleans up code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants