Reduce memory consumption when parsing large objects and arrays.#101
Reduce memory consumption when parsing large objects and arrays.#101iv-menshenin wants to merge 7 commits intovalyala:masterfrom
Conversation
|
This patch helped mitigate memory spikes in our application. The memory usage chart was clearly improved. Since this seems to be a positive change, I wonder if maintainers (cc @valyala) can consider it? Thank you. |
|
Hi @iv-menshenin, could you provide a way to validate your improvements? |
It's working on our production nativerent as long as my PR lives. (≈500 RPS) |
|
No, I'm asking for a simple reproduction. How did you test you improvements? Is it possible to verify this on the benchmarks of this repo? If not, can you provide one? |
I'll see what I can do. |
|
@StarpTech Here's what happens after the improvement: If required, I can do a comit with this test file to demonstrate what said |
|
@iv-menshenin that looks promising. Is there a big performance drop for smaller files? A test file would be great. We maintain a fork which we actively maintain. We have already incorporated a lot of other changes that didn't get merged in this repository. Would you be interested in contributing to it? |
No. There isn't
I will add a new case
I would like to. |
|
@StarpTech |
|
In the meantime, I'm giving some validation in this PR You can get this memory consumption graph via pprof if you run the tests with the following parameters: No matter how many times I run the tests, I see 0 memory allocations as a result, but profiling gives a clearer picture of what's going on. And what is happening is consuming more than 1 gigabyte of memory And this is what the graph looks like after my improvements I think it's pretty clear |
|
Is the issue resolved? We have met the same question, cache.getValue waste great memory. |


We use fastjson in our project and recently I found an unpleasant issue when processing huge json files (we have 25 megabytes and more than 300 thousand elements in the array):
when cache.vs reaches its limit and performs memory reallocation, if the GC fails to clean up the memory in time, we experience a sharp spike in memory usage graphs.
The funniest part is that we barely noticed this, because our application kept crashing with OOM, so we had to temporarily disable the limits for testing.
After working with pprof for a while, I found where the most memory allocations are happening and worked on improvements. I tried several options and this one turned out to be the most efficient, as shown by the tests in our environment.
If you don't accept this pull request, it's okay, then we'll just continue using our fork.
Thank you.