Minimizing lagging scroll movements while utilizing overflow-y: scroll;

I am currently working on a 2 column layout, where the right-hand column contains a scrollable list displaying a maximum of 200 items (implemented using a ul with overflow-y: scroll;).

However, I have noticed that scrolling through the right-hand column is causing some lag, particularly on lower-end hardware.

While analyzing the Chrome timeline, I observed significant delays in the "Update Layer tree" process whenever I scrolled through the column. Is there a way to determine why this update is taking so long and which CSS properties are impacting performance the most? Clicking on it only provides information about its duration without any additional details.

The individual li elements contain CSS styles like filters, transforms, and box-shadows that seem to be affecting the scrolling performance negatively. Removing each SASS file one by one improves the performance gradually (eliminating the lag after removing all CSS), but identifying the specific problematic CSS properties through this method is challenging.

I wonder if there are any features in the Chrome timeline that could assist in addressing this issue?

Although I attempted to use the will-change CSS property to enhance scrolling by promoting it to a separate layer for hardware acceleration, it did not yield significant improvements.

No JavaScript events are triggered during scrolling.

Maintaining fewer than 200 items in the list is not a feasible solution.

To demonstrate the issue, I have created an example with a longer list of items: https://github.com/jooj123/jank/blob/master/scroll.html

An intriguing observation is that removing the overflow-y: scroll; property from .map-search__results in the example significantly enhances scrolling smoothness and eliminates the lag. What could be causing such a dramatic impact?

Here is the Chrome timeline data, showing prolonged "Update Layer tree" sections: https://i.sstatic.net/UYGy8.png

Solution:

Paul's recommendation regarding will-change: transform is highly effective, especially this insight:

"Add will-change: transform;. Once added, the "repaints on scroll" rect is gone."

It is important to note that this approach may not always work depending on your codebase. Verify that the "repaints on scroll" indicator is disabled by checking the scroll performance issues. In my case, I also had to disable a -webkit-clip-path property (present in my actual codebase, not in the provided demo) that was set in one of the child divs. See:

https://i.sstatic.net/rEHMl.gif

Answer №1

I recently tested out a test page provided by you and examined it carefully.

When faced with scrolling performance issues, my go-to solution is to toggle some of the checkboxes in the Rendering pane:

https://i.sstatic.net/LvFZf.png

This immediately highlights a div labeled as "repaints on scroll". To further confirm this, I checked the experimental Layers panel:

https://i.sstatic.net/nOGlC.png

(I simply right-clicked in the tree and selected "Show internal layers", by the way)

In most cases, high "update layer tree" costs are due to either numerous small layers or a few excessively large ones. However, in this instance, we have neither of those issues. Instead, we have a scrolling layer that lacks composited scrolling.

Composited scrolling translates to fast scrolling, which is typically the default behavior. Nevertheless, situations like this resort to "main thread scrolling", which is significantly slower and less efficient. Fortunately, the link crbug.com/381840 suggests a forthcoming fix that should automatically address this particular test case. But until then, we can implement a workaround.

A Helpful Workaround

You mentioned trying the will-change property without success, but upon my own experimentation, it proved to be quite effective. It should be applied to the element with an overflow setting, such as the .map-search__results selector. Simply add will-change: transform;. Once implemented, the "repaints on scroll" issue disappears. Subsequent measurements using the timeline feature confirm significant improvement.

Here's a comparison between the before and after states:

link to viewer

Best of luck!

Answer №2

If you're experiencing a noticeable issue with scrolling on your website, try toggling individual styles in the developer tools to isolate the problem. By unchecking styles one by one and observing how it affects scrolling, you can pinpoint the specific rule causing the issue instead of sifting through entire CSS files. If you utilize sourcemaps in your CSS, locating and adjusting the problematic rule in your actual CSS files should be straightforward.

If you're not familiar with using the styles tab in Chrome developer tools, simply open the inspector tool and select the elements you suspect are causing trouble. The associated styles for the selected element will be displayed in the styles tab, allowing you to disable them individually. You can also delve deeper into nested items using the inspector tool.

UPDATE:

Upon reviewing your code closely, I discovered that setting overflow on the ul element may be contributing to the choppy scrolling behavior. Instead of applying overflow directly to the ul, consider placing it on the containing div element (.right-content) and setting its height to 100%. This adjustment resolved the scrolling issue by simplifying the calculation process when moving items, resulting in smoother performance.

Comparing the timelines shown in the images above reveals the impact of this change. In the original version with overflow set on the ul, numerous li items are being painted during the update tree process, leading to inefficient rendering. On the other hand, after removing overflow from the ul and applying it to the parent div, only the ul itself is painted, streamlining the rendering process and improving performance significantly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for assigning one file input to another file input?

Quite an unusual question, I admit. The crux of the matter is my utilization of a fantastic tool known as cropit. With this tool, we have the ability to upload an image, preview it, and then manipulate it according to our preferences. HTML: <div align ...

Incorporate a division based on the selection made from a jQuery dropdown menu

Is there a way to dynamically display a div to the right of a drop-down menu based on the user's selection using DOM manipulation? For reference, you can view an example of my current progress here: http://jsbin.com/#/afojid/1/edit The initial drop ...

- Bullet point: Table heading alignment variation

When it comes to centering a <th> element inside an <li>, different browsers have different approaches. In Internet Explorer, Edge, and Safari, the <th> is center-justified. However, in Chrome, Firefox, and Opera, it's left-justifie ...

Inspecting HTML elements with Capybara for class and ID attributes

Trying to locate an element and use Capybara for validation. There's a specific element that I want to check for using page.should have_css. <i class="ui-grid-icon-cancel" ui-grid-one-bind-aria-label="aria.removeFilter" aria-lab ...

I am puzzled by the fact that the center cell of my table is longer than the surrounding cells

I'm currently working on a project that involves creating a webpage. I have a table, and when I execute the code, I notice that the center cell appears longer than the rest of the cells. table,td,tr{border: 1px solid red; } <!document html> ...

The necessity of using Adobe Photoshop for optimizing a Web Template

My interest lies in utilizing web templates, such as the one referenced here:- templete However, within its details tab, it specifies that the following software is required:- Adobe Photoshop CS+ Sublime Text2 or later, Notepad++, Dreamweaver CS5.5+(Co ...

Discover the significance of a data attribute's value for effective comparisons

I have a loop that generates random numbers and positions to create 4 answer choices for users. Now, I am trying to determine the value of the clicked button and compare it to the position of the correct answer. However, whenever I try to do this, it retu ...

"Resizing a Javascript file resulting in the creation of a faulty base64

I have been attempting to resize images on the client side using HTML5 before uploading. However, it seems that the base64 string is broken as it contains spaces, line breaks, and other unexpected characters. Even after removing them, the string remains br ...

Can you explain the significance of the characters '& > * + *' in JSX (CSS)?

When using material UI, the progressbar demo includes lines of JSX code like this: '& > * + *': { marginTop: theme.spacing(2), }, Can you explain what the selector '& > * + *' represents in this context? ...

css issue with opacity transition not functioning properly

My website is designed to display images in a table, but some of them are Stock Photos, so I need to indicate the source. I want the source to appear when the user hovers over the picture. For this purpose, I have assigned the source tag to a class (.PicSo ...

what is the process for customizing the default font in tailwindcss?

I recently started a new project using React, and I have integrated a custom font in my index.css file. I have also included the necessary font files. @tailwind base; @tailwind components; @tailwind utilities; @tailwind variants; @import url(assets/font/ir ...

Optimizing Your Click-to-Call Phone Number for Your Website

When building a responsive webpage using Twitter Bootstrap, I noticed that certain elements are only visible on smaller resolutions like tablets and phones. On an iPhone with OS7, I found that leaving phone numbers as plain text without a link allows the ...

Tips for showcasing a full body height background

I'm currently working on a project where I need to display random background images when the body loads. To achieve this, I've created a function. However, I'm facing an issue where the images are filling up the entire page, making it very l ...

Obtain the beginning and ending positions of a substring within a larger string

As a beginner in the world of AngularJS and web development, I am faced with a challenge. I have a specific string that is currently selected on a tab, like so: var getSelectedText = function() { var text = ""; if (typeof window.getSelection !== "un ...

When floated to the right, the element is being pushed onto the next line in Firefox

Within a div, there are four elements. I specifically want the last element to be positioned on the far right, so I applied float: right to it. However, in Firefox, the last element gets pushed to the end of the next line instead. This issue does not occ ...

Tips for capturing the dx dy SVG attribute using CSS

Seeking advice on the most effective way to access the dx dy SVG attribute in CSS. If this is not feasible, what would be the best approach in JavaScript? ...

Tips for dividing a div into percentages while maintaining a constant width for a div on the left side

I need help with creating a layout that involves 4 boxes. The first box (box1) should have a width of 50px on the left side, while the remaining 3 boxes should fill in the rest of the screen and be resizable. Can someone guide me on achieving this layout? ...

How to target a class with a specific number in CSS selectors

My mobile hybrid application is built with Sencha Touch 2 and requires some customization based on the iOS version it's running on. In my Sass stylesheet, I originally had the following selector: .x-ios-7 { /* add iOS7 customizations here */ } How ...

dynamically passing arguments to an onclick function

I am experiencing an issue with the following HTML element that has an onclick() function dynamically attached. When trying to call the function, it throws an error stating that "ST" is not defined. The variable passed as name is something like "ST-123". C ...

Customizing Bootstrap Style for the 'btn-xs' Size Using a New CSS Class

Hey there, I'm diving into Bootstrap for the first time and I'm looking to tweak the 'btn-xs' class to adjust the height, width, and padding. I want to make the button smaller and reduce the text size as well. I attempted to create a n ...