Avoid MimeType garbage creation #22340
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
While profiling Spring web applications (MVC and WebFlux), it seems that
MimeType
(throughMediaType
) is creating a significant amount of garbage that could be avoided.toString()
result ofMimeType
instances, since it cannot change and this method is called many times on hot pathsMediaType.parseMediaType
is called multiple times, for each request; this could be backed by a simple LRU cache implementation to avoid re-parsing known media typesMimeTypeUtils.parseMimeType
parsing code can be improved; a draft implementation shows +40% throughput and -10% allocation.MimeTypeUtils
andMediaType
both have static sections where well-known types are parsed; changing those fromAPPLICATION_JSON = MimeType.valueOf(APPLICATION_JSON_VALUE);
toAPPLICATION_JSON = new MimeType("application", "json");
leads to a bit of duplication but consistently reduces garbage and CPU usage at startup time (approx. 10ms).The text was updated successfully, but these errors were encountered: