Skip to content

Use Netty's optimized UTF-8 encoding if available [SPR-17558] #22090

@spring-projects-issues

Description

@spring-projects-issues

Mark Paluch opened SPR-17558 and commented

CharSequenceEncoder uses CharBuffer.wrap and charset.encode to encode String data to its binary representation. There can be two optimizations made here:

  1. CharSequenceEncoder uses typically UTF-8 encoding and Java's UTF-8 encoder requires significant computing time. It would make sense to detect this case and whether netty is on the class path to use netty's optimized UTF-8 encoding via ByteBufUtil.writeUtf8(…)
  2. Encoding creates a new unpooled ByteBuffer when calling Charset.encode. Netty's ByteBufUtil.encodeString() can encode a String to a pooled buffer that reduces GC pressure.

See also attached profiling snapshot.


Attachments:

Referenced from: commits 5a8b8b1, 6361b0c, a00be62, 4955d08

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions