Skip to content

Conversation

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Nov 13, 2025

Additional details

Improves performance of hovering or pinning a command to highlight elements within a snapshot. The improvements would be most evident when the command queries A LOT of elements. There are a few strategies employed here:

  • Reducing the calls to getComputedStyles
  • Batching the calls to get offset for element we want to highlight - so the first 50 highlights WILL SHOW UP FIRST, and the other highlights will asynchronously come in. So, when the command shows as 'pinned', it is possible that all of the elements are not highlighted at that point.
  • Cancel the asynchronous calls to highlight the el when another call is made to highlight elements on another snapshot.

Steps to test

  • Open a test that targets 3,000 items that have distinct positions in the DOM

How has the user experience changed?

Before

When hovering/clicking to pin a snapshot that targets 3,000 elements completely locks up the UI for 15+ seconds. You cannot hover or pin any other snapshots during this time - or see any highlights.

Screen.Recording.2025-11-14.at.12.42.00.PM.mov

After

When hovering/clicking to pin a snapshot that targets 3,000 element - highlights and pinning shows up within 2 seconds (although ALL of the elements are not done highlighting). You can see when all of the elements finish highlighting in my video where the console.log logs when it's complete.

Screen.Recording.2025-11-14.at.12.38.48.PM.mov

You can click and hover around fairly quickly (feels a little laggy) since the previous batch of highlighting now cancels when you go to highlight other snapshots.

Screen.Recording.2025-11-14.at.12.48.46.PM.mov

PR Tasks


Note

Speeds up Command Log snapshot highlighting by caching getComputedStyle results, batching DOM operations/positioning, and canceling in-flight highlight work; adds tests and minor refactors.

  • Performance – runner (packages/app/src/runner):
    • AutIframe.highlightEl: batch-create highlight layers off-DOM, append via DocumentFragment, then batch-position with requestAnimationFrame; add cancelation via _currentHighlightingId.
    • dimensions.ts: cache a single getComputedStyle call; return display, transform, zIndex, and offsetWidth/Height; optimize setOffset.
    • _addElementBoxModelLayers: accept precomputed dimensions, avoid extra style reads; store positions as data attrs; use shared INT32_MAX.
    • DOM querying in restoreDom/removeHighlights optimized to reduce redundant lookups and batch removals.
  • Driver (packages/driver/src/dom):
    • dimensions.ts: cache computed styles (padding/border/margin) in one pass.
    • blackout.ts: build blackout div via native DOM and compact style string.
  • Tests:
    • New specs validating single getComputedStyle call and no redundant calls when dimensions provided (aut-iframe.cy.tsx, dimensions.cy.tsx).
  • Docs/Changelog:
    • Update cli/CHANGELOG.md noting improved Command Log snapshot highlighting performance.

Written by Cursor Bugbot for commit c761e8f. This will update automatically on new commits. Configure here.

@jennifer-shehane jennifer-shehane self-assigned this Nov 13, 2025
@jennifer-shehane jennifer-shehane changed the title perf: reduce calls to getComputedStyles for element dimension calculations perf: reduce calls to getComputedStyles for element dimension calculations (used for snapshots) Nov 13, 2025
@cypress
Copy link

cypress bot commented Nov 13, 2025

cypress    Run #67402

Run Properties:  status check failed Failed #67402  •  git commit c761e8f6fd: add body gaurd
Project cypress
Branch Review snapshot-reduce-get-computed-style
Run status status check failed Failed #67402
Run duration 18m 52s
Commit git commit c761e8f6fd: add body gaurd
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 2
Tests that were flaky  Flaky 13
Tests that did not run due to a developer annotating a test with .skip  Pending 1098
Tests that did not run due to a failure in a mocha hook  Skipped 4
Tests that passed  Passing 26690
View all changes introduced in this branch ↗︎

Warning

Partial Report: The results for the Application Quality reports may be incomplete.

UI Coverage  45.76%
  Untested elements 187  
  Tested elements 162  
Accessibility  98%
  Failed rules  4 critical   8 serious   2 moderate   2 minor
  Failed elements 101  

Tests for review

Failed  src/runner/aut-iframe.cy.tsx • 2 failed tests • app-ct

View Output

Test Artifacts
AutIframe._addElementBoxModelLayers > should not call getComputedStyle when dimensions are provided Test Replay
AutIframe._addElementBoxModelLayers > should call getComputedStyle only once when dimensions are not provided Test Replay
Flakiness  issues/28527.cy.ts • 1 flaky test • 5x-driver-electron

View Output

Test Artifacts
issue 28527 > fails and then retries and verifies about:blank is not displayed Test Replay Screenshots
Flakiness  commands/navigation.cy.js • 1 flaky test • 5x-driver-chrome:beta

View Output

Test Artifacts
src/cy/commands/navigation > #page load > sets initial=true and then removes Test Replay
Flakiness  commands/waiting.cy.js • 1 flaky test • 5x-driver-chrome:beta

View Output

Test Artifacts
... > errors > throws when route is never resolved Test Replay
Flakiness  e2e/origin/config_env.cy.ts • 1 flaky test • 5x-driver-chrome:beta

View Output

Test Artifacts
cy.origin- Cypress.config() > serializable > overwrites different values in secondary if one exists in the primary Test Replay
Flakiness  issues/28527.cy.ts • 1 flaky test • 5x-driver-chrome:beta

View Output

Test Artifacts
issue 28527 > fails and then retries and verifies about:blank is not displayed Test Replay Screenshots

The first 5 flaky specs are shown, see all 13 specs in Cypress Cloud.

@jennifer-shehane jennifer-shehane changed the title perf: reduce calls to getComputedStyles for element dimension calculations (used for snapshots) perf: improve performance of pinning snapshots during hover / pin Nov 14, 2025
@@ -0,0 +1,137 @@
import { AutIframe } from './aut-iframe'
Copy link
Member Author

@jennifer-shehane jennifer-shehane Nov 14, 2025

Choose a reason for hiding this comment

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

I don't think these are in an optimal form for unit tests, but it doesn't seem we have vitest or any other convention here but Cypress tests. I'd like to have a test for this, so welcome to if there's a better way to do this.

@@ -0,0 +1,58 @@
import { getElementDimensions } from './dimensions'
Copy link
Member Author

Choose a reason for hiding this comment

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

Another 'unit' test

Comment on lines +11 to +17
const style = `border: none !important; margin: 0 !important; padding: 0 !important; position: absolute; top: ${top}px; left: ${left}px; width: ${width}px; height: ${height}px; background-color: black; z-index: 2147483647;`

const div = document.createElement('div')

div.className = '__cypress-blackout'
div.style.cssText = style
$body.append(div)
Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not helpful much, but looked into this function a bit for the blackout of screenshots.


const getElementDimensions = ($el: JQuery<HTMLElement>) => {
const el: HTMLElement = $el.get(0)

Copy link
Member Author

Choose a reason for hiding this comment

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

We should consolidate these but I didn't want to get distracted with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants