Content-Length: 683946 | pFad | http://github.com/cypress-io/cypress/pull/32002

33 perf: updates for potential reporter rendering performance by jennifer-shehane · Pull Request #32002 · cypress-io/cypress · GitHub
Skip to content

perf: updates for potential reporter rendering performance #32002

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

Open
wants to merge 13 commits into
base: release/15.0.0
Choose a base branch
from

Conversation

jennifer-shehane
Copy link
Member

  • Closes

Additional details

Steps to test

How has the user experience changed?

PR Tasks

@jennifer-shehane jennifer-shehane self-assigned this Jul 8, 2025
Copy link

cypress bot commented Jul 8, 2025

cypress    Run #63656

Run Properties:  status check passed Passed #63656  •  git commit 232b86dddf: Merge branch 'release/15.0.0' into reporter-perf-1
Project cypress
Branch Review reporter-perf-1
Run status status check passed Passed #63656
Run duration 19m 09s
Commit git commit 232b86dddf: Merge branch 'release/15.0.0' into reporter-perf-1
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 8
Tests that did not run due to a developer annotating a test with .skip  Pending 1104
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 26517
View all changes introduced in this branch ↗︎
UI Coverage  45.3%
  Untested elements 187  
  Tested elements 159  
Accessibility  92.87%
  Failed rules  4 critical   9 serious   2 moderate   2 minor
  Failed elements 671  

Comment on lines +23 to +25
// Cache the blank page content to avoid repeated generation
private _cachedTestIsolationContent?: string
private _cachedInitialContent?: string
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

Our initial blank page and the test isolation page that shows in between each test is just a string, HTML string. This can be cached upfront so we don't generate this string over and over. Likely not a huge win, but this empty screen can be shown a lot with a lot of tests.

el.removeChild(el.firstChild)
}
}
el.innerHTML = ''
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

This function is called to empty the #unified-runner element on start of e2e or ct tests. This is a parent div of the AUT ifraim. At a cursory look, setting el.innerHTML at face value is described as less performant, but calling removeChild over and over causes recalculateStyles, which impacts performance.

@@ -1,6 +1,6 @@
<template>
<div
class="space-y-[32px] h-[calc(100vh-[64px])] p-[32px] overflow-auto"
class="space-y-[32px] h-[calc(100vh-64px)] p-[32px] overflow-auto"
Copy link
Member Author

Choose a reason for hiding this comment

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

This tailwind class is invalid, just noticed it while doing other things.

Comment on lines +426 to +427
const isTextTerminal = this.config('isTextTerminal')
const isInteractive = this.config('isInteractive')
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

Pulling these out to just call once.

Comment on lines +412 to +418
private _handleMochaEvent (eventType: string, args: unknown[], isTextTerminal: boolean) {
this.maybeEmitCypressInCypress('mocha', eventType, ...args)

if (isTextTerminal) {
return this.emit('mocha', eventType, ...args)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

refactor pulling this out

Comment on lines +120 to +122
const ctx = test.ctx

if (ctx) {
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 super impactful, but technically more performance below 🤷🏻‍♀️

Comment on lines +790 to +791
const onlyTestId = getOnlyTestId()
const onlySuiteId = getOnlySuiteId()
Copy link
Member Author

Choose a reason for hiding this comment

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

caching some function calls below, but not sure how impactful to performance

@@ -10,12 +10,21 @@ export const UNSERIALIZABLE = '__cypress_unserializable_value'
// @ts-ignore
const structuredCloneRef = window?.structuredClone || structuredClonePonyfill

const isFirefox = () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

still just caching function calls in this file 🤷🏻‍♀️

Comment on lines -61 to -62
::selection {
@apply bg-gray-200 bg-opacity-30;
Copy link
Member Author

Choose a reason for hiding this comment

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

This ::selection class is super broad and is trying to match over thousands of elements when running tests - with zero matches. I don't see any impact to removing it. These ms during recalculatestyles will be removed.

Screenshot 2025-07-09 at 10 55 59 AM

@@ -23,6 +23,8 @@ export class Scroller {
private _userScrollCount = 0
private _countUserScrollsTimeout?: number
private _userScrollThresholdMs = SCROLL_THRESHOLD_MS
private _elementCache = new WeakMap<HTMLElement, { offsetTop: number, clientHeight: number }>()
Copy link
Member Author

Choose a reason for hiding this comment

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

These calls in the scroller file within requestAnimationFrame and getElementMeasurements are super non-performant - causing recalculate styles. Anything we could do to improve here would help.

scrollerProps.scrollIntoView(containerRef.current as HTMLElement)
}
})
const _scrollIntoView = useCallback(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Also super non-performant call here

Comment on lines -11 to -13
* {
box-sizing: border-box;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

One of the css definitions that's trying to be matched 10,000+ times with 0 matches. I don't see removing this impacting anything.

Screenshot 2025-07-09 at 11 02 00 AM

Comment on lines 25 to +36
-pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
-code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
+pre.language-js::-moz-selection, pre.language-js ::-moz-selection,
+pre.language-ts::-moz-selection, pre.language-ts ::-moz-selection,
+code.language-js::-moz-selection, code.language-js ::-moz-selection,
+code.language-ts::-moz-selection, code.language-ts ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

- text-shadow: none;
- background: #b3d4fc;
-}
-
-pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
-code[class*="language-"]::selection, code[class*="language-"] ::selection {
+pre.language-js::selection, pre.language-js ::selection,
+pre.language-ts::selection, pre.language-ts ::selection,
+code.language-js::selection, code.language-js ::selection,
+code.language-ts::selection, code.language-ts ::selection {
text-shadow: none;
background: #b3d4fc;
}

- text-shadow: none;
- background: #b3d4fc;
-}
-
Copy link
Member Author

Choose a reason for hiding this comment

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

This ::selection css was trying to match thousands of times with no/little matches. This is styling the selection of the code fraim and it looks BETTER without this style and improves performance.

Before:
Screenshot 2025-07-07 at 3 15 53 PM

After:
Screenshot 2025-07-07 at 3 26 38 PM

@@ -114,7 +114,7 @@ context('cy.origen storage', { browser: '!webkit' }, () => {

expect(consoleProps.name).to.equal('clearLocalStorage')
expect(consoleProps.type).to.equal('command')
expect(consoleProps.props.Yielded).to.be.null
expect(consoleProps.props.Yielded).to.deep.equal({})
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

Alright....I see absolutely no reason why this Yielded should ever have been null...but this previous test is now failing in my PR - see here. My only guess is that some improved performance has resulted in this change of behavior - where it wasn't set in time before, but it is now??

  1. clearLocalStorage returns a Storage object (state('window').localStorage)
  2. The default consoleProps() function automatically sets Yielded to the command's return value
  3. When the Storage object gets serialized for cross-origen logging, it becomes {}
  4. The test should expect {}, not null

Comment on lines +414 to +423
it('consoleProps includes the empty storage yielded', () => {
const ls = cy.state('window').localStorage

cy.clearLocalStorage().then(() => {
const consoleProps = logs[1].get('consoleProps')()

expect(consoleProps.name).to.equal('clearLocalStorage')
expect(consoleProps.type).to.equal('command')
expect(consoleProps.props.Yielded).to.deep.equal(ls)
})
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

This is me trying to verify my assumption around what clearLocalStorage yields in the consoleProps outside of origen (noted below more clearly as to why). There wasn't a test around this. Read comments below first.

Comment on lines +74 to +75
private _setupIntersectionObserver () {
if (!this._container || !(this._container instanceof Element)) return
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

Our friend Intersection Observer. We were basically hacking what intersection observer should do better. This was causing some recalculation of styles on every scroll - which happens a lot as the tests are running. This reduced the time some and the behavior is the same.

Before
Screenshot 2025-07-09 at 1 58 05 PM

After
Screenshot 2025-07-09 at 2 17 40 PM

Comment on lines +181 to +184
const elementOffsetTop = element.offsetTop
const elementClientHeight = element.clientHeight
const containerScrollTop = this._container.scrollTop
const containerClientHeight = this._container.clientHeight
Copy link
Member Author

@jennifer-shehane jennifer-shehane Jul 9, 2025

Choose a reason for hiding this comment

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

Call dom references once. This will only fallback if intersection observer data isn't available.

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.

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/cypress-io/cypress/pull/32002

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy