H
H
Hanry6542021-12-15 03:36:23
Node.js
Hanry654, 2021-12-15 03:36:23

What to do if an array in a variable takes a lot of RAM?

There is an array of data

const array = [
    {
        a: "test", 
        b: "test", 
        c: "test", 
    }
    // ... 6200 elements
]

It takes more than 4GB of memory, I heard about node --max-old-space-size=32000 dist/index.jsit, but it's still not an option, since the array can reach up to 20k+ elements, is it possible to somehow optimize this?
(Data from the array is used all the time)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hanry654, 2021-12-18
@Hanry654

I read the file through without specifying the encoding

fs.readFile(path.join(__dirname, '..', '..', 'test.txt'))

And I wrote strings to an array as a buffer, as soon as I added an encoding specification, the problem was fixed
fs.readFile(path.join(__dirname, '..', '..', 'test.txt'), 'utf-8')

P
pfg21, 2021-12-15
@pfg21

effective optimization of large volumes of data is done in databases ?? they are now for every taste and color ...
why reinvent your own wheel when everything has been knurled for a long time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question