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.

graphql-anywhere: replace `JSON.stringify` call on very hot code path

See original GitHub issue

Hey, folks! We use the propType module from graphql-anywhere in quite a few places in our app & we’re finding that the JSON.stringify call here causes a noticeable slowdown when we make a particularly large data request during local development (ie, when prop-type checking is performed).

The size of our returned data is relatively large and contains many nested types in its query, which I suppose is what’s causing this code path to be so hot.

Here’s what I see when using Chrome’s performance profiling feature after making a couple of these large network requests: Screen Shot 2020-01-02 at 2 20 28 PM

I replaced this JSON.stringify call with a hard-coded string for comparison, which drove this line’s execution time to 10s of ms.

Using JSON.stringify is nice for the level of detail it gives in the error, but would you accept an alternative that makes this line run faster? Using JSON.stringify causes such a large slowdown during local development that I think we’ll have to remove this package from our app if a change isn’t possible.

A simple solution might be to just make the error ${info.resultKey} missing.

Happy to make a PR if you’d be open to it!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
benjamncommented, Jan 8, 2020

I’m open to improving this, but I would just point out that we (the Apollo Client team) thought we had written the code such that JSON.stringify would not be called in production, where performance matters most, thanks to ts-invariant and rollup-plugin-invariant.

This issue is specifically pointing out that JSON.stringify is called unnecessarily in development, which is true, but the stringification payload needs to be pretty huge before that becomes a noticeable problem, and there’s no performance penalty in production, because long error messages are stripped in production builds.

Also, just in case anyone who reads this is new to JavaScript performance, JSON.stringify is one of the most obsessively optimized tools we have available to us as web developers, so in general there’s no way to do what it does any faster with handwritten JS. You can only pass less data to it, or stop calling it unnecessarily, which is what we’re considering doing here.

0reactions
hwillsoncommented, Apr 29, 2021

Closing since graphql-anywhere is no longer something we’re supporting (details: https://github.com/apollographql/apollo-client/issues/5744#issuecomment-571988792). Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON.stringify replacer - how to get full path - Stack Overflow
"As a function, it takes two parameters: the key and the value being stringified. The object in which the key was found is...
Read more >
GraphQL Code Libraries, Tools and Services
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >
How to connect your GraphQL API to AWS data sources
In this post, we'll focus on how to build GraphQL resolvers for AWS data sources, such as Amazon DynamoDB, Amazon Aurora, and Amazon...
Read more >
Changelog - Cypress Documentation
Subsequent cy.mount calls within the same test will remove the last mounted component ... Using a cypress.json configuration file is no longer supported....
Read more >
Hot Module Replacement - SurviveJS
For example, style-loader can update your CSS without forcing a refresh. Implementing HMR for styles is ideal because CSS is stateless by design....
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