We have a service that uses graphQL. This graphQL file is parsed into an AST. It is a huge map (~7 Mb) that contains atoms, small binaries, lists, and maps.
The problem is that we have to analyse the schema every time a request comes to our server. So the AST gets copied to the process heap. For example, if we have 100 concurrent requests, it takes 700 MB of memory. We expect the schema to grow so it will be worse.
My question is, is there a better way to store the AST or any trick what we can use, to optimize the memory usage?
Thanks, we might write it back.
We used to use the persistent_term function, but the schema changes from time to time, so it drops the performance for seconds.
If the updates are relatively few and you’re okay with ”leaking” memory for a while, consider placing the schema under a new persistent_term key for each version (index it by an atomic or whatever). That way you can shift the cost of garbage collecting the old schemas until off-peak hours.