question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some of the unit tests are too slow

See original GitHub issue

Currently it takes ~40s to run the test suite. It used to be much faster, but we added a lot of unit tests since then and some of them are bottlenecks. We can use karma-time-stats-reporter plugin to discover which of the tests are slowing down the suite. Here’s the list of the slowest ones:

4707ms Map #flyTo move to requested center and zoom, and call zoomend once                                                           
2877ms Map #flyTo flyTo start latlng == end latlng                                                                                   
2862ms TileLayer number of kittens loaded Loads 290, unloads 275 kittens on MAD-TRD flyTo()                                          
2699ms GridLayer number of 256px tiles loaded in synchronous animated grid @800x600px Loads 290, unloads 275 tiles on MAD-TRD flyTo()
1329ms ImageOverlay #getCenter should open popup at the center                                                                       
808ms  Popup L.Map#openPopup moves the map over a long distance to the popup if it is not in the view (keepInView)                   
683ms  Map.ScrollWheelZoom changes the option 'wheelPxPerZoomLevel'                                                                  
612ms  Path #events can add a layer while being inside a moveend handler                                                             
358ms  Map.ScrollWheelZoom changes the option 'wheelDebounceTime'                                                                    
314ms  LineUtil #polylineCenter computes center of a small line and test it on every zoom                                            
309ms  Map.ScrollWheelZoom zooms out while firing 'wheel' event                                                                      
307ms  Map.Keyboard plus/minus keys zoom in                                                                                          
306ms  Map.ScrollWheelZoom scrollWheelZoom: 'center'                                                                                 
306ms  Map.Keyboard does not move the map if disabled no move north                                                                  
306ms  Map.Keyboard does not move the map if disabled no zoom in                                                                     
306ms  Map.Keyboard arrow keys move the map west                                                                                     
305ms  Map.Keyboard plus/minus keys zoom out                                                                                         
305ms  Map.Keyboard arrow keys move the map east                                                                                     
305ms  Map.Keyboard arrow keys move the map north                                                                                    
303ms  Map.Keyboard arrow keys move the map south                                                                                    
297ms  Map.ScrollWheelZoom zooms in while firing 'wheel' event                                                                       
266ms  Map #containerPointToLayerPoint return point relative to LayerPoint                                                           
263ms  Map.DoubleClickZoom doubleClickZoom: 'center'                                                                                 
260ms  Map.DoubleClickZoom zooms out while dblclick and holding shift                                                                
256ms  Map #layerPointToContainerPoint return point relative to ContainerPoint                                                       
252ms  TileLayer #setUrl fires only one load event                                                                                   
244ms  Map.DoubleClickZoom zooms in while dblclick                                                                                   
220ms  Control.Layers sortLayers keeps original order by default                                                                     
193ms  Map.Drag touch events reset itself after touchend                                                                             
191ms  Map.TouchZoom Dragging is possible after pinch zoom            

It would be nice to fix some of these if they don’t depend on such a long running length. Faster test suite means less friction when developing.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rjacksoncommented, Oct 8, 2022

I think this is all the savings I’ve found from all >100ms tests. The ones that remain I believe are bottlenecked by animation frames, as mentioned above.

Reductions so far:

Test Before After Reduction
Popup L.Map#openPopup keepInView (speed up one test, add another 2) 812ms 802ms 10ms
Map.ScrollWheelZoomSpec 1881ms 332ms 1549ms
Map.DoubleClickZoomSpec 812ms 47ms 765ms
Path #events can add a layer while being inside a moveend handler 611ms 5ms 606ms
Map #layerPointToContainerPoint return point relative to ContainerPoint 269ms 1ms 268ms
Map #containerPointToLayerPoint return point relative to LayerPoint 258ms 1ms 257ms
TileLayer #setUrl fires only one load event 251ms 13ms 238ms
Marker #setIcon pan map to focus marker with no iconSize 103ms 1ms 102ms
Marker #setIcon pan map to focus marker 102ms 1ms 101ms
Total (sum of above) 5099ms 1204ms 3895ms
1reaction
rjacksoncommented, Oct 8, 2022

A good chunk of our tests appear bottlenecked by the speed that Chrome running in headless mode will deliver animation frames. I’ve noticed this looking into tests using Leaflet/prosthetic-hand, as they seem to run twice as fast in a non-headless browser.

The tests overall do run a lot quicker in a windowed instance of Chrome. I suspect this is due to GPU acceleration.

npm run test -- --browsers Chrome
Test Headless time Headful time Difference
Total time 11.465s 7.186s 1.59x
Net time 10.898s 6.763s 1.61x
Slowest tests
GridLayer number of 256px tiles loaded in synchronous animated grid @800x600px Loads 290, unloads 275 tiles on MAD-TRD flyTo() 2700ms 1349ms 2.00x
TileLayer number of kittens loaded Loads 290, unloads 275 kittens on MAD-TRD flyTo() 2678ms 1344ms 1.99x
Popup L.Map#openPopup moves on setLatLng after initial autopan 531ms 515ms (same)
Map #setMaxBounds avoid subpixel / floating point related wobble 303ms 302ms (same)
Popup L.Map#openPopup moves the map over a short distance to the popup if it is not in the view (keepInView) 267ms 257ms (same)
Map #containerPointToLayerPoint return point relative to LayerPoint 253ms 254ms (same)
Canvas #events does fire mousedown on layer after dragging map 198ms 81ms 2.44x
Map.TouchZoom Dragging is possible after pinch zoom 196ms 89ms 2.20x
Map.Drag touch events reset itself after touchend 195ms 97ms 2.01x
Map #flyTo flyTo start latlng == end latlng 115ms 108ms (same)

I’m not sure if we want to do anything with this information. I don’t think it’s practical to run a windowed version of Chrome every time we run the tests, as the window popping up is quite disruptive. Nevertheless I wanted to document the finding 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How slow is too slow for unit tests? - Stack Overflow
A unit test that takes 1/10th of a second to run is a slow unit test... If [unit tests] don't run fast, they...
Read more >
9 Ways To Make Slow Tests Faster - Semaphore CI
At Semaphore, we've seen our fair share of tests and have identified 9 ways to make your slow tests faster.
Read more >
Unit tests running slow - does not seem to use all cores
Adding some more information. It seems to start out fast, using >90% CPU and running 4 of 5 tests in parallel, but then...
Read more >
Unit Tests Slow Me Down - Medium
Actual nitty gritty debugging is faster when you're doing it via unit test rather than stepping through a debugger. Most debugging time is...
Read more >
Unittest run all tests is extremely slow #17295 - GitHub
Running my particular test suite takes 1.2s while running the tests using the vscode extension takes at least several seconds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found