11 ms·
I find the entire history of improvements to Java’s String class enjoyable to read about. Over the years, the implementation of Java’s String class has been im
by stevoski 1y ago
I find the entire history of improvements to Java’s String class enjoyable to read about.
Over the years, the implementation of Java’s String class has been improved again and again, offering performance improvements and memory usage reduction. And us Java developers get these improvements with no work required other than updating the JRE we use.
All the low-hanging fruit was taken years ago, of course. These days, I’m sure most Java apps would barely get any noticeable improvement from further String improvements, such as the one in the article we’re discussing.
- niuzeta 1y agoI love hearing more about this, especially the historical context, but don't have a good java writeups/articles on this. Would you mind sharing some suggestions/pointers? I'd very much appreciate it.
- stevoski 1y agoA good starting point is Joshua Bloch’s Effective Java. He shares some stories there from Java’s early days, and - at least in passing - mentions some aspects of the String class’s history.
- niuzeta 1y agoAh, I certainly remember these anecdotes! What other resources would you recommend(even the tidbits) could there be for more modern Java? The original article like this one should be treasured.
- DaiPlusPlus 1y ago> Would you mind sharing some suggestions/pointers? I would, but unfortunately I got a NullPointerException. I suggest you try Rust instead; its borrow checker will ensure you can't share pointers in an unsafe manner.
- wging 1y agoString compression was one. tl;dr: the JVM supports Unicode for strings, but uses 1-byte chars for strings where possible (previously it was UTF-16), even though it's not actually doing UTF-8. Depending on what sort of document you're looking for, you might like either the JEP: https://openjdk.org/jeps/254 https://openjdk.org/jeps/254 or Shipilev's slides (pdf warning): https://shipilev.net/talks/jfokus-Feb2016-lord-of-the-strings.pdf https://shipilev.net/talks/jfokus-Feb2016-lord-of-the-string... Shipilev's website (https://shipilev.net/#lord-of-the-strings https://shipilev.net/#lord-of-the-strings), and links from the JEP above to other JEPS, are both good places to find further reading. (I think I saw a feature article about the implementation of the string compression feature, but I'm not sure who wrote it or where it was, or if I'm thinking about something else. Actually I think it might've been https://shipilev.net/blog/2015/black-magic-method-dispatch/ https://shipilev.net/blog/2015/black-magic-method-dispatch/, despite the title.)
- niuzeta 1y agoAbsolutely love it. Thanks a lot. A fancy hit me yesterday and I've been looking through JDK's String commit history to see little tidbits that I could grab. Shipilev's website looks like a fascinating resource. I appreciate the pointer!
- cempaka 1y agoThis is a good video that goes over a ton of the optimizations, especially around concatenation: https://youtu.be/z3yu1kjtcok?si=mOdZ5sh5rp8LNyap https://youtu.be/z3yu1kjtcok?si=mOdZ5sh5rp8LNyap
- niuzeta 1y agoI appreciate it! I will take a look this weekend,
- neuroelectron 1y agoWhen I started my career in software development, SDE, and soon advanced to SRE, I hated Java. The extreme OOP paradigm made enterprise class situations impossible to understand. But after a few short years, I began to appreciate it as a real, battle hardened ecology. Now, I consider it much better than modern trends such as Rust and Python. These kinds of niche optimizations are still significant. The OOP model allows them to be implemented with much less fanfare. This is in the context of billion-dollar platforms. With some basic performance testing and API replays, we're saving thousands of dollars a day. Nobody gets a pat on the back. Maybe some pizza on Friday.
- jimmaswell 1y agoI've seen Java described as made for companies to be able to rotate out mediocre programmers as efficiently as possible without letting them mess things up easily, and it makes a lot of sense from that perspective. Barebones semantics to the point of being Spartan (can't even define your own operator overloads), easy to take another class and copy it with small modifications but not mess it up for anyone else (inheritance).. Then there's C# which most anyone who's enthusiastic about software dev will find far nicer to work with, but it's probably harder for bargain basement offshore sweatshops to bang their head against.
- nradov 1y agoThe lack of operator overloading is a bit annoying but in practice seldom a real problem. An operator is just a funny looking method. So what. There are worse fundamental problems in Java. For example the lack of a proper numeric tower. Or the need to rely on annotations to indicate something as basic as nullabilty.
- saagarjha 1y agoIt’s a massive annoyance when working with any sort of numeric code. Or custom collections. Or whatever else the standard library enjoys that nobody else gets to use.
- 1y ago
- bradhe 1y ago> no work required other than updating the JRE we use Have you tried updating production usage of a JRE before??
- microflash 1y agoI have done it multiple times for different versions of Java with nominal effort. Of course, difficulty may vary depending on a project. With projects like OpenRewrite [1] and good LLMs, things are a lot easier these days. [1]: https://docs.openrewrite.org https://docs.openrewrite.org
- znpy 1y agoYes. I moved a few repository from java 8 up to Java 21. Java 8 -> 9 is the largest source of annoyances, past that it's essentially painless. You just change a line (the version of the JRE) and you get a faster JVM with better GC. And with ZGC nowadays garbage collection is essentially a solved problem. I worked on a piece of software serving almost 5 million requests per second on a single (albeit fairly large) box off a single JVM and I was still seeing GC pauses below the single millisecond (~800 usec p99 stop the world pauses) despite the very high allocation rate (~60gb/sec). The JVM is a marvel of software engineering.
- g0db1t 1y ago[dead]
- paulddraper 1y agoThe flip side is that for years Java developers have been dealing with suboptimal strings with nothing to do about it.