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

[BUU] Producers selects are to be populated on focus #12524

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cyrillefr
Copy link
Contributor

What? Why?

When visiting page admin/products (in V3 mode), each select is populated via the classical Rails way.

But each select carries the same data, which can be some overload for the producers selects that may carry a lot of data.
My solution is instead to put the producers data once in a html element template.
Each select is only populated with its default.
Then, on focus, it is populated.
Therefore, no more copying 10 times the same options for the 10 selects.
Also, it is now the browser job to populate the focused select.
One group of data is written on the page instead of 10, which reduces the server work.

I have created for that a Stimulus controller that inherit from tom-select, and not a StimulusReflex one.

What should we test?

  • In V3 toggled mode, as an admin or producer
  • Visit admin/products
  • There should be no change with the current display of selects.
  • The same behaviour should be seen: change one item and page should notice.
  • Changing a producer for a product should work as expected.
  • From 10 items or more, a search input must be visible, but not under 10 or 10

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@rioug rioug added the feature toggled These pull requests' changes are invisible by default and are grouped in release notes label May 28, 2024
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice approach ! I just have one suggestion to make it a little bit better, see my comment.

Also did you try to reproduce the issue demonstrated by Filipe with this change: #12482 (comment) ?

@cyrillefr
Copy link
Contributor Author

Hello @rioug ,

I have not tested the case shown by @filipefurtad0.
I do not have enough data locally.
Furthermore, I do not see clearly the issue.
I see overlapping selects but it is because clicks are fast paced.
May be @filipefurtad0 can test my branch ?

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Very clever solution.

Can you elaborate a bit more what the advantage of this is?

Effects that I could imagine, but I haven't measured any of this:

  • The transferred HTML is smaller. This doesn't really matter with compression though because repetitions are well compacted.
  • The browser might render the page quicker because it doesn't have to render all the options to start with.
  • The browser does more work on focus because it has to build the options which would otherwise already be rendered.
  • Were the producer options cached before? If not then this new approach will save us a lot of database queries and building of options on the server. If it was cached then there's no big benefit in rendering it only once.

My main question is probably: Which solution is less work for the browser? And maybe the answer depends on the size of the product set and how many products you edit. If the list is big and you edit only one product, the new on-demand building of options is probably better. If the user edits every product on the page then it doesn't help.

I guess that you are on the right path here but I don't find the answer straight forward.

Anyway, very well done!

}

fetchProducers() {
if ((Object.keys(this.control.options).length) > 1) return false;
Copy link
Member

Choose a reason for hiding this comment

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

What if there is only one option? It will try to populate this on every focus, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, on each focus, fetchProducers will be called.

At first, there is only one option (the selected one), so the select will be populated.
After that, the number of options will always be superior to 1 and there will be not new attempt to populate the select.

@mkllnk mkllnk requested a review from rioug May 28, 2024 23:09
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Looks good know 👍 It will be interesting to see if resolved the issue that Filipe found.

@filipefurtad0 filipefurtad0 self-assigned this May 30, 2024
Comment on lines 1 to 2
%template{ id: "producer_options"}
= options_for_select(producer_options, product.supplier_id)
Copy link
Member

Choose a reason for hiding this comment

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

I just came across this PR and had a quick look. Thanks for working on this!

This partial is repeated for every product row, yet it appears the intention was to only include the template once. When the controller searches for the element by ID, it will simply find the last one (standard browser behaviour).

This is ok, it would work, and as Maikel mentioned the compression will take care of most of it. But it looks like it should be very easy to remove the duplication by moving the template to another partial. So if you have time, feel free to go ahead update it ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aaah, my bad. I just pushed a correction.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, but i can see:

  • this is still repeated for every product.
  • producer_options is no longer needed in product_row
  • options_for_select doesn't need a second parameter for selected value (tomselect will need to choose it for each product when initialised)

But first let's see if we can confirm a performance improvement before progressing.

@dacook dacook changed the title Producers selects are to be populated on focus [BUU] Producers selects are to be populated on focus Jun 3, 2024
@filipefurtad0 filipefurtad0 added no-staging-AU A tag which does not trigger deployments, indicating a server is being used pr-staged-fr staging.coopcircuits.fr and removed no-staging-AU A tag which does not trigger deployments, indicating a server is being used labels Jun 3, 2024
@filipefurtad0
Copy link
Contributor

Hey @cyrillefr ,
Thank you for working on this.

I went through the scenarios you've suggested:

  • In V3 toggled mode, as an admin or producer
  • Visit admin/products
  • There should be no change with the current display of selects - OK -> I could not spot a difference visually or functionally
  • The same behaviour should be seen: change one item and page should notice - OK
  • Changing a producer for a product should work as expected - OK

Unfortunately, I could still reproduce the issue:
image

Indeed, it is related to fast pace clicking. It is noticeable how dropdowns take some time to open, after clicking. From a usability point of view, it is difficult to say, in a qualitative way, whether the PR brings improvement - although this was my first impression. In any case, I've tried to measure this with Lighthouse. Here are the results:

Before this PR

image

After this PR

image

We can see that:

  • Total Blocking Time indeed is reduced
  • Interaction to Next Paint (INP) is increased

It's hard to say whether these results are meaningful. I guess we might need more runs to account for variability.

In any case, and on this last point:

  • From 10 items or more, a search input must be visible, but not under 10 or 10

I'm not sure I understand the test case. I've switched to a producer with one product only, but can still find the search input in the page:

image

What do you think @cyrillefr ?

@filipefurtad0 filipefurtad0 added feedback-needed and removed pr-staged-fr staging.coopcircuits.fr labels Jun 3, 2024
@cyrillefr
Copy link
Contributor Author

Hello @filipefurtad0 ,

I don't know how to improve the usability with long lists, maybe it has to do with too much data is select boxes.

Regarding the input and the 10 threshold, it is the input box that appears on each select box that has 11 or more options and not the input that appears on top of the page.

 - added a new Stimulus controller to display one line selects
 - that are to be populated when getting focus to avoid repeating
 - 10 times same option lists
 - on focus, select is populated by the data stored in template.
 - data that used to be source for each select (and so repeated) is
 - now stored once in a template
- comments
- id of template as a parameter
- little clean-up
- added a new partial to avoid template repetition
@sigmundpetersen sigmundpetersen force-pushed the BUULoadOnlyOnceOptionsListOnAdminBulkEditScreenForProductsAdminV3 branch from bb4f9e4 to 9adbb1d Compare June 3, 2024 20:45
@dacook
Copy link
Member

dacook commented Jun 3, 2024

it is the input box that appears on each select box that has 11 or more options

Here's a (low quality) screenshot of one for example:
Screenshot 2024-06-04 at 9 09 42 am

@dacook
Copy link
Member

dacook commented Jun 4, 2024

I just had a look at a super-admin user on current fr_prod and fr_staging, and found that there's already quite a delay when opening producer dropdowns.
When testing on dev with a smaller dataset, I found no delay whatsoever.

The reported increase in delay is a concern. It looks like there are different performance bottlenecks to look at.

So from what I can see, unfortunately this PR doesn't seem to bring a benefit. But it has helped us learn a bit more about the performance, thanks for your contribution. I think we should pause on this, re-evaluate the problems and prioritise along with other priorities.

I'll discuss in #backoffice-ui-uplift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature toggled These pull requests' changes are invisible by default and are grouped in release notes feedback-needed
Projects
Status: In Progress ⚙
Development

Successfully merging this pull request may close these issues.

[BUU] Optimisation: long select lists repeated
5 participants