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

chore: destroy source maps consumers when spec finishes #23708

Merged
merged 15 commits into from
Sep 13, 2022

Conversation

emilyrohrbough
Copy link
Member

@emilyrohrbough emilyrohrbough commented Sep 7, 2022

While profile Cypress to determine the memory impact we have, noticed we aren't explicitly cleaning up our Source Map Consumers. The documentations calls out the need to manually clean this up ourselves to free up wasm data. This may or may not impact our memory footprint, however we felt it'd be worth cleaning up to see if it helps.

https://www.npmjs.com/package/source-map#sourcemapconsumerprototypedestroy

Apart of #23391
Apart of #21135

  • [n/a] Have tests been added/updated?
  • [n/a] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [n/a] Has a PR for user-facing changes been opened in cypress-documentation?
  • [n/a] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 7, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Sep 7, 2022



Test summary

40020 0 3359 0Flakiness 3


Run details

Project cypress
Status Passed
Commit 7828ea3
Started Sep 13, 2022 1:48 PM
Ended Sep 13, 2022 2:04 PM
Duration 15:35 💡
OS Linux Debian - 11.3
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

e2e/origin/config_env.cy.ts Flakiness
1 cy.origin- Cypress.config() > serializable > overwrites different values in secondary, even if the Cypress.config() value does not exist in the primary
cypress/source_map_utils.cy.js Flakiness
1 driver/src/cypress/source_map_utils > .extractSourceMap > is performant with multiple source map comments in file
e2e/origin/commands/connectors.cy.ts Flakiness
1 cy.origin connectors > .each()

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990
Copy link
Contributor

cc @ZachJW34 we talked about source maps in the context of stack traces earlier, this might be relevant/interesting to you.


const sourceMapExtractionRegex = /\/\/\s*[@#]\s*sourceMappingURL\s*=\s*(data:[^\s]*)/g
const regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,([a-zA-Z0-9+/]+={0,2})/ // matches data urls

let sourceMapConsumers = {}
let sourceMapConsumers: Record<string, BasicSourceMapConsumer> = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use Map, I think it makes the intention a bit more clear.

} catch (err) {
// ignore unable to match regex. there's nothing we
// can do about it and we don't want to thrown an exception
if (err.message === 'Maximum call stack size exceeded') return null
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth checking if this error is the same in FF and WebKit

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest checking the error type instead, but it looks like the error type is inconsistent (InternalError in Firefox; RangeError in Chrome and Safari.), but the error message is the same across browsers.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Too_much_recursion

Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

I tried it out - everything works as expected, I did not look into measuring the memory consumption yet (need to do some research on how best to even measure this).

I wanted to know how destroy worked, it looks like it frees up memory allocated in wasm: https://github.com/mozilla/source-map/blob/master/lib/source-map-consumer.js#L426-L431

Let's see how it goes - either way, this is obviously an improvement, always good to free up memory.

@lmiller1990 lmiller1990 self-requested a review September 8, 2022 07:47
@BlueWinds BlueWinds self-requested a review September 12, 2022 16:01
packages/driver/src/cypress/source_map_utils.ts Outdated Show resolved Hide resolved
} catch (err) {
// ignore unable to match regex. there's nothing we
// can do about it and we don't want to thrown an exception
if (err.message === 'Maximum call stack size exceeded') return null
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest checking the error type instead, but it looks like the error type is inconsistent (InternalError in Firefox; RangeError in Chrome and Safari.), but the error message is the same across browsers.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Too_much_recursion

packages/driver/src/cypress/source_map_utils.ts Outdated Show resolved Hide resolved
@@ -403,15 +403,9 @@ class $Cypress {
break

case 'runner:end':
// mocha runner has finished running the tests
$scriptUtils.destroySourceMaps()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we call $sourceMapUtils.destroySourceMapConsumers() directly, and avoid the indirection of adding this to $scriptUtils?

@emilyrohrbough emilyrohrbough merged commit 75a9f96 into develop Sep 13, 2022
@emilyrohrbough emilyrohrbough deleted the destory-source-consumers branch September 13, 2022 14:10
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 13, 2022

Released in 10.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.8.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants