Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Reading a JSON file uses a lot of memory in node

I am a bit surprised that reading a 274.9MB json file and storing it on a variable as an array of objects causes a 1.1GB usage of Resident Set Size memory in node.js.

How can this be? it seems a bit excessive.

import { readFile } from 'fs/promises'

const raw = await readFile('big.json', 'utf8')
const file = JSON.parse(raw)

console.log('Length: ', file.length)
console.log(
  `Memory: ${Math.round((process.memoryUsage().rss / 1024 / 1024) * 100) / 100} MB`
)
Length: 920885
Memory: 1193.05 MB

Here are the contents of one object as an example

{
  keyword: '1 hour circuit training',
  url: 'https://www.pinterest.com/pin/457467274629879495',
  rank: 1,
  page: 1,
  type: 'inline_images',
  title: 'image result',
  domain: '-',
  sitelinks: false
}
.... 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is about the expected size. At least half a gig is being taken up by the string content of big.json - JavaScript uses UCS-2, so each character must necessarily take 2 bytes. Note you're not freeing it (no delete statement), so it's still referred-to from the stack when you take the measurement. Hard to tell exactly what the memory layout of an "array of objects" is, but objects, being hash maps, do have some overhead. If they contain strings, then again, count each character double. All in all, this memory usage is realistic and not entirely unexpected.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!