spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Avoid creating byte[] multiple times in StringHttpMessageConverter

Open brucelwl opened this issue 4 months ago • 8 comments

When calculating the ContentLength and writing data to the OutputStream in StringHttpMessageConverter, calling str.getBytes(charset) repeatedly will result in unnecessary array objects occupying memory

https://github.com/spring-projects/spring-framework/blob/09917fad7bca9b3997522f0a75d6319203f2127f/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java#L103-L106

https://github.com/spring-projects/spring-framework/blob/09917fad7bca9b3997522f0a75d6319203f2127f/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java#L122-L129

brucelwl avatar Jul 30 '25 18:07 brucelwl