mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
612a63c0f1
Prior to this commit, `MediaType.parseMediaType` would already rely on the internal LRU cache in `MimeTypeUtils` for better performance. With that optimization, the parsing of raw media types is skipped for cached elements. But still, `MediaType.parseMediaType` would first get a cached `MimeType` instance from that cache and then instantiate a `new MediaType(type, subtype, parameters)`. This constructor not only replays the `MimeType` checks on type/subtyme tokens and parameters, but it also performs `MediaType`-specific checks on parameters. Such checks are not required, as we're using an existing `MimeType` instance in the first place. This commit adds a new protected copy constructor (skipping checks) in `MimeType` and uses it in `MediaType.parseMediaType` as a result. This yields interesting performance improvements, with +400% throughput and -40% allocation/call in benchmarks. This commit also introduces a new JMH benchmark for future optimization work. Closes gh-24769