Bug 36441 - Improve performance of Item::is_bundle
Summary: Improve performance of Item::is_bundle
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: David Gustafsson
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-27 18:12 UTC by David Gustafsson
Modified: 2025-01-14 10:38 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Before (282.93 KB, image/png)
2024-03-27 18:19 UTC, David Gustafsson
Details
After (283.48 KB, image/png)
2024-03-27 18:19 UTC, David Gustafsson
Details
Bug 36441: Improve performance of Item::is_bundle (1.82 KB, patch)
2024-03-27 18:24 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36441: Improve performance of Item::is_bundle (1.79 KB, patch)
2024-03-27 18:28 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36441: Add comment explaining why replacing the DBIx call (863 bytes, patch)
2024-03-27 18:36 UTC, David Gustafsson
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Gustafsson 2024-03-27 18:12:11 UTC
For a biblio with a large number of holdings (which could be the case for serials for example) Item::is_bundle is one of the main culprits in terms of performance. I know it's usually frowned upon substituting DBIx queries with the DBI-equivalent, but think there are few other option in this case and should be very unlikely to cause any future regressions. Attached before and after flamegraphs to illustrate the difference in performance.
Comment 1 David Gustafsson 2024-03-27 18:19:29 UTC
Created attachment 164023 [details]
Before
Comment 2 David Gustafsson 2024-03-27 18:19:42 UTC
Created attachment 164024 [details]
After
Comment 3 David Gustafsson 2024-03-27 18:24:00 UTC
Created attachment 164025 [details] [review]
Bug 36441: Improve performance of Item::is_bundle

Perform count using DBI-query in Item::is_bundle to
significantly improve performance.

To test:
1) Go to the details page of a bibio with a large number
   of holdings holdings, preferably more than a hundred,
   and take note of page load time.
3) Apply patch
4) Reload the page and take note of page load time.
5) There should be an improvement of about 10-15%
6) Ensure tests in t/db_dependent/Koha/Item.t pass

Sponsored-by: Gothenburg University Library
Comment 4 David Gustafsson 2024-03-27 18:28:17 UTC
Created attachment 164026 [details] [review]
Bug 36441: Improve performance of Item::is_bundle

Perform count using DBI-query in Item::is_bundle to
significantly improve performance.

To test:
1) Go to the details page of a bibio with a large number
   of holdings holdings, preferably more than a hundred,
   and take note of page load time.
3) Apply patch
4) Reload the page and take note of page load time.
5) There should be an improvement of about 10-15%
6) Ensure tests in t/db_dependent/Koha/Item.t pass

Sponsored-by: Gothenburg University Library
Comment 5 David Gustafsson 2024-03-27 18:36:31 UTC
Created attachment 164027 [details] [review]
Bug 36441: Add comment explaining why replacing the DBIx call
Comment 6 David Nind 2025-01-03 01:32:01 UTC
The patch still applies.

Is this affected by or still relevant after Bug 33568 - Use the REST API to display items on the staff biblio detail view added to Koha 24.05? (I'm not a developer...)
Comment 7 Thibault Keromnès 2025-01-13 14:55:13 UTC
I've tested with 175 items on a biblio and it's not enough to see a difference in the load time before and after the patch (the load time varies too much). 
We need to try with more items.
Comment 8 Thibault Keromnès 2025-01-14 10:38:18 UTC
To test : you can go to any biblio - new item - add multiple items, to create hundreds of them. Then on the biblio page you have to select "All" items so it (otherwise only 20 items will load)

For 600 items, the network response times on 4 tests before applying :
- 24434 ms
- 23750
- 24062
- 24239
after applying : 
- 23233 ms
- 23401
- 23593
- 23883
Can somebody see a difference in speed? 
As of now the test plan doesn't allow to find a difference, or there's isn't a real difference.