In one of the Spring Boot applications I'm working on there's a REST API with a POST API endpoint which allows a user to upload a file by adding its base64 encoding to the request body as follows :
{
"file": <base64 String>
}
This JSON gets mapped to a corresponding DTO object which then gets processed.
Now let's say I send in a file of about 1Mb in size. By the time the message is received by the REST controller, the heap size increases by up to 6x as much memory as the size of the file. In this case it's about 6Mb increase in heap size. I measured this with jconsole / VisualVM. For even larger files of 30Mb I see an increase in heap size of about 90Mb.
So I added a breakpoint to the controller method to check what is consuming memory but it's not easy to navigate through that data, and all I found was the DTO and the JSON String representing the file.
What else could be consuming the memory, and is there a way to minimize it? Possibly changing the API itself?
EDIT : Possible duplicate of parsing to json using jackson-mapper causes