Memory leak in `destr` package, Nuxt 3 production usage
See original GitHub issueHello, @pi0.
I found a memory leak, that affects Nuxt 3 framework, because the destr
package is used as default parseResponse
option in the ohmyfetch
, that used in the Nuxt 3 useFetch()
function as $fetch
.
Memory leak
Flamegraph
Table
Memory usage
Temporary fix for Nuxt 3
-
Create a local TypeScript file (
lib/use-fetch.ts
) with copy ofuseFetch()
function. -
Add custom
parseResponse()
function:import type { FetchOptions } from 'ohmyfetch'; /** * Parse response * @description Replace of `destr()` function to prevent memory leak * @param responseText */ const parseResponse: FetchOptions['parseResponse'] = (responseText) => { // Send empty string if zero length if (responseText.length === 0) { return ''; } try { return JSON.parse(responseText); } catch (_e) { return responseText; } };
-
Replace
_fetchOptions
constant in the copy ofuseFetch()
function:const _fetchOptions = { ...opts, parseResponse, cache: typeof opts.cache === 'boolean' ? undefined : opts.cache }
-
Use patched
useFetch()
function instead of build-in.
Because, right now there is no way to provide custom parseResponse()
function as option of the useFetch()
without error.
Best wishes, Sergey.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Huge Memory leak If the "meta" option is set true #94 - GitHub
Yes, we resolved a memory leak in the linked PR. The current leak is due to using a Vue 3 library (vueuse/head) and...
Read more >Nuxt huge memory usage / leakage and how to prevent
I was in the under standing that Vue.use is OK if it is not inside export functionally? On the #3 we use $nuxt.$on...
Read more >Avoiding Memory Leaks - Vue.js
Memory leaks in Vue applications do not typically come from Vue itself, rather they can happen when incorporating other libraries into an application....
Read more >Vue and Nuxt Performance Optimization Checklist
Read the comprehensive and in-depth technical article summarizing how to improve the site performance with efficient use of Vue.js and Nuxt.
Read more >Memory Leak Nuxt On Build - ADocLib
js. Your project is considerably large. This is common in most of the node projects. Wrong auth, axios module configurations. There could be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dargmuesli it’s part of the Datadog APM.
The
dd-trace-js
package was used for tracing. Under the hood it’s using the@datadog/pprof
package, fork ofpprof
.The Datadog Continuous Profiler used for visualization.
API responses is nested tree JSON documents, 50—100 KB size.
Restart of a container.
Yes.
Node.js 16.14.2, a Docker image based on the https://github.com/astefanutti/scratch-node.