question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Netty 5] Is AsciiString still useful ?

See original GitHub issue

JDK 9+ includes JEP 254 Compact String which can use a byte[] instead of a char[] as the backing storage for String in some situations. The primary reason for introducing AsciiString was to reduce memory for storage of headers. We should investigate if String can now be used instead. We would likely have to wrap String to be able to override the hashCode algorithm to be case insensitive. If we do decide to keep AsciiString the constant memory overhead for smaller string is quite high because we maintain array/offset to avoid copying in some situations. We should investigate if this is beneficial/necessary as it can also lead to longer retention of larger byte[] objects.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Bennett-Lynchcommented, Nov 13, 2018

As part of this, can we also re-evaluate API’s that return a CharSequence rather than a String?

I think CharSequence should be the preferred input type, but String should be the only return type.

String is the de facto string representation used throughout most of Java, and I sometimes have to write cumbersome logic like this:

CharSequence cs = NettyUtilMethod.get();
return (cs == null) ? null : cs.toString();
0reactions
idelpivnitskiycommented, Mar 19, 2020

@normanmaurer In ServiceTalk, we have a similar class AsciiBuffer, that implements CharSequence interface. But in ServiceTalk motivation is different: we do that to avoid copying of the header names and values (we can do that because we do not use pooled memory) and to optimize the writes (avoid serialization of String) side. According to our benchmarks it gives advantages on JDK11. So, “reduce memory for storage of headers” is not the primary motivation in our use-case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netty 5.0.0.Alpha5 released - Netty.news
Buffer leak detection has been improved, and numerous leaks have been fixed as a result. Mutation methods have been removed from AsciiString ....
Read more >
AsciiString (Netty API Reference (4.1.85.Final))
This class was designed to provide an immutable array of bytes, and caches some internal state based upon the value of this array....
Read more >
New and noteworthy in 5.0 - Netty.docs
This document walks you through the list of notable changes and new features in the major Netty release (since 4.1) to give you...
Read more >
New and noteworthy in 4.1 - Netty.docs
You will find this class useful when you deal with a US-ASCII or ISO-8859-1 string. For instance, the HTTP codec and STOMP codec...
Read more >
NetUtil xref - Netty
If failed to get the value, {@code 200} is used as a 75 * default value for ... 6 || 508 // a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found