You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
H2O: Reuse JSON generators across HTTP requests (#2713)
Previously, whenever a memory allocation for the sake of a JSON
generator was performed, the application used the memory pool
associated with the HTTP request, so the generator was freed
after the response was sent (since the memory pool was
subsequently destroyed), and a new one was created for the next
request. In this way the memory management overhead for the JSON
generator was reduced.
However, it has been discovered that some of the memory
allocation sizes associated with the JSON generator are above
the limit imposed by libh2o, so the latter resorts to calling
malloc() directly, which defeats the purpose of using a memory
pool in the first place.
The solution is to separate the memory management for the JSON
generators from the memory pools managed by libh2o, and to reuse
generators across HTTP requests. After a response is sent, the
state of each generator is fully reset (as if the generator has
just been constructed), so that when it is reused, the new JSON
response is created from scratch. Reinitializing the generator
is much cheaper than freeing it and allocating a new one.
Since this approach increases the memory usage of the
application, the maximum number of JSON generators that can be
reused is configurable. Any generator above that limit will be
deallocated immediately as soon as it is no longer used.
0 commit comments