primefaces: DataTable: Paging slow when using selection

Describe the bug

Having datatable with selection. Using selectionPageOnly=“false”. Tried to generate 7000 records when i found out page change is taking too long. Still not sure what exactly is wrong, but on our spring boot server, a single page change takes 2-5 minutes. Unfortunately on reproducer which is on Jetty takes less time but it is still noticable 10-15s.

  1. First note is that i need to have all records selected on start / table load, that is why i put all the records inside selection list before page load instead using some ajax to call table.selectAllRows() method. I did notice when i click the unselect all and then again select all checkbox, the requests are lot faster (200-400ms) which is great…

  2. Second note is that on reproducer i had to put this line in Jetty config file. These form settings might have the speed difference effect. "<Set name="maxFormContentSize" type="int">600000</Set>"

Using Primefaces 13.0.10, but tried on 14.0.1 with the same result. Would be great to have fix made into 13.0.11 where i am waiting for similar/related bugfix https://github.com/primefaces/primefaces/issues/11885. Thank you.

Reproducer

table-paging.zip

Expected behavior

Selected record count should not have effect on page change speed.

PrimeFaces edition

Elite

PrimeFaces version

13.0.10

Theme

No response

JSF implementation

Mojarra

JSF version

4.0.6

Java version

17

Browser(s)

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

For each element in datatable you have to traverse the whole “selected” list and check equals on the rowKey on both elements?

Iterate through list would be a better term (traverse is more tree related) but yes, to fill DataTable#selection attr you need to iterate over every rowKey and find in the loaded data, the corresponding bean.

From performance point of view it would be much better to store “selected” items in some hash-map like structure, like you mentioned above: https://github.com/primefaces/primefaces/issues/12196#issuecomment-2195311409

I believe I did a PR in the past that got reverted for some reasons, but anyway using lazy mode is the easiest/quite efficient way to go about it

When I use “select all”, the datatable uses https://github.com/ALL instead of 7000 elements, so it runs much faster?

Yes, it’s one single rowKey (it’s an alias, nothing to do with PFS @all btw…) that says “all row keys” which will run the algorithm much faster as it is only one rowKey (and not 7000…)

It seems like this algorithm is triggered on each pagination event, why is that? We want to display certain page, why do we re-calculate the whole datatable?

Because pagination triggers a new HTTP request, and therefore requires to decode the dataTable component. I guess there could be a way of improving the algorithm, but in a situation like yours, you’re supposed to use lazy mode, so not sure it worth the effort to cover this use case

Hi, I tested the reproducer project from @chaloma1 with following scenario:

  1. Page load - load time is OK
  2. Click on Second page - it takes 12s
  3. Click on Third page - it takes 12s
  4. Back to second page - it takes 12s
  5. Unselect all - no request (client side event)
  6. Click on First page - it takes 12s - all items are selected (probably fixed in 13.0.11)
  7. Unselect all - no request (client side event)
  8. Select all - no request (client side event)
  9. Click on Second page - it takes 40ms !!
  10. Clicking on various pages - it takes 40ms

Please see attached GIF with this scenario: datatable_performance

The scenarios I was talking above were the two situations from jprofiler - 12s call (with quadratic complexity) vs 40ms call