News for hackers. Stuff that matters.
Re:Strings Just Got Faster by stevoski on Friday May 02, 2025 @05:10PM (#43874607)
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.

Re:Strings Just Got Faster by niuzeta on Friday May 02, 2025 @05:40PM (#43874847)
I 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.
Re:Strings Just Got Faster by stevoski on Friday May 02, 2025 @05:48PM (#43874893)
A 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.
Re:Strings Just Got Faster by niuzeta on Friday May 02, 2025 @06:49PM (#43875276)
Ah, 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.
Re:Strings Just Got Faster by DaiPlusPlus on Friday May 02, 2025 @08:51PM (#43875968)
> 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.

Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @06:06AM (#43878000)
I know it's a tongue in cheek reply but..

You can't share "pointers" in an unsafe manner in Java. Even data races are completely memory safe.

Re:Strings Just Got Faster by niuzeta on Saturday May 03, 2025 @04:25PM (#43881968)
I did laugh, so there is that.
Re:Strings Just Got Faster by wging on Saturday May 03, 2025 @01:12AM (#43877001)
String 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

or Shipilev's slides (pdf warning): https://shipilev.net/talks/jfokus-Feb2016-lord-of-the-string...

Shipilev's website (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/, despite the title.)

Re:Strings Just Got Faster by niuzeta on Saturday May 03, 2025 @04:24PM (#43881962)
Absolutely 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!

Re:Strings Just Got Faster by cempaka on Saturday May 03, 2025 @09:14AM (#43878847)
This is a good video that goes over a ton of the optimizations, especially around concatenation: https://youtu.be/z3yu1kjtcok?si=mOdZ5sh5rp8LNyap
Re:Strings Just Got Faster by niuzeta on Saturday May 03, 2025 @04:22PM (#43881945)
I appreciate it! I will take a look this weekend,
Re:Strings Just Got Faster by neuroelectron on Friday May 02, 2025 @09:14PM (#43876097)
When 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.

Re:Strings Just Got Faster by jimmaswell on Friday May 02, 2025 @09:59PM (#43876305)
I'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.

Re:Strings Just Got Faster by nradov on Friday May 02, 2025 @10:18PM (#43876371)
The 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.

Re:Strings Just Got Faster by saagarjha on Friday May 02, 2025 @11:02PM (#43876555)
It’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.
Re:Strings Just Got Faster by ivan_gammel on Friday May 02, 2025 @10:36PM (#43876456)
I remember the times on one of professional forums, where there was lots of questions about architecture in C# sections and almost none in Java section. Abundance of tools creates abundance of possibilities to get confused about what’s right. In Java many design decisions converged to some dominant design long time ago, so you no longer think about it and focus on business. It’s sometimes as bad as getter verbosity (thankfully record style is getting traction), but in most cases it’s just fine.
Re:Strings Just Got Faster by atomicnumber3 on Saturday May 03, 2025 @01:51AM (#43877119)
I really don't think this stance aged well, even if it was closer to true way back when. IMO the spartan language is now Go, and Java has ended up the boring open source workhorse. The jvm is very performant compared to many stacks these days (python Ruby node) while still having a very compelling concurrent programming story, and has a lot of nice language feature things ever since 8 and onwards. Lambdas and streams are the big 8's, but I think virtual threads growing up and even new things like scoped variables are really compelling reasons to build a new thing in java right now.
Re:Strings Just Got Faster by knorker on Saturday May 03, 2025 @02:42AM (#43877289)
> Java has ended up the boring open source workhorse.

This statement surprised me. I can't even remember last time I ran any opensource Java.

Re:Strings Just Got Faster by dgoldstein0 on Saturday May 03, 2025 @03:15AM (#43877395)
Off the top of my head? Bazel is the Java program I use the most. Hadoop/hive and similar stuff also heavily Java but I'm not sure how much that's in use anymore
Re:Strings Just Got Faster by knorker on Saturday May 03, 2025 @05:47AM (#43877935)
I'm not saying there's no Java in open source. And I'm aware of the projects you mention. I don't run them though. And they definitely don't qualify as "the boring open source workhorse".

There are a couple of Java projects, and even one or two kind of successful ones. But Java in open source is very rare, not the boring workhorse.

If I worked on a project that used Bazel, then sure, I'd use Bazel every day.

But which is "the boring workhorse" of open source, if I gave you the option of Java, Make, Linux, gcc, llvm, .deb, would Java really be "the" one?

Sure, maybe you could exclude most of those as not being "boring", like llvm. But "make" wins by any measure. And of course, it's almost by definition hard to think about the boring workhorse, because the nature of it is that you don't think about it.

Checking now, the only reason I can find java even being installed on my dev machines is for Arduino IDE and my Android development environment. Pretty niche stuff, in the open source space.

Re:Strings Just Got Faster by ivan_gammel on Saturday May 03, 2025 @02:28PM (#43881051)
Most Java applications nowadays are based 100% on open source stack with hundreds of libraries and frameworks and Java dominates enterprise space, so it is a huge open source workhorse, just more obscure than Linux, gcc etc.
Re:Strings Just Got Faster by knorker on Saturday May 03, 2025 @04:30PM (#43882019)
Ok, we clearly have an extremely different definition of the word "the" workhorse of open source.

It doesn't mean "more than zero projects are Java based". Nor does it mean "most (opensource?) Java applications are based on open source". That latter is borderline circular, only Oracle legal shenanigans makes it not circular.

> and Java dominates enterprise space

I said nothing about enterprise. Clearly Java is HUGE in enterprise.

> so it is a huge open source workhorse

That sentence took a strange turn. Enterprise, and then back to open source?

> just more obscure than Linux, gcc etc.

Obscure? I'd expect Java to be about as strong a brand as Linux. Among developers in general I'd expect gcc to be orders of magnitude more obscure. There's no programmer out there who has not heard of Java, but many have never heard of gcc.

Re:Strings Just Got Faster by ivan_gammel on Sunday May 04, 2025 @04:18AM (#43885344)
> Ok, we clearly have an extremely different definition of the word "the" workhorse of open source.

You said what it is not, but forgot to share your own definition.

>That sentence took a strange turn. Enterprise, and then back to open source?

What makes you so surprised? One does not exclude another, enterprise users are users too. Most of things in Java world aren’t client-side, so many users won’t observe them directly, but open source Java technology is doing a lot of work for them, constituting significant share of the code base.

Re:Strings Just Got Faster by dfedbeef on Saturday May 03, 2025 @10:25AM (#43879238)
Ghidra also
Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @06:03AM (#43877992)
Half of the internet is literally running that.. like unless you deliberately avoid Java stacks, you will come across it. It's one of the top 3 ecosystems in size, with JS and python being the other 2 contenders.
Re:Strings Just Got Faster by knorker on Saturday May 03, 2025 @10:39AM (#43879327)
Internet? Yes. But that was not the topic at hand.
Re:Strings Just Got Faster by concerndc1tizen on Saturday May 03, 2025 @05:54AM (#43877950)
The problem with the JVM, compared to Go, is the GC; it requires a lot of reserved memory. Go programs use far less. And the SDK is bulky, which can be a problem for container images - although arguably it should be considered irrelevant, as you only download base images once, if done correctly.
Re:Strings Just Got Faster by homebrewer on Saturday May 03, 2025 @07:29AM (#43878366)
You're not supposed to use the runtime directly these days. jlink allows you to strip unnecessary things (like documentation for the runtime itself), extract only those parts of the runtime you need (though your project must use modules to support that), and then aggressively compress it all getting a pretty small package that runs on an empty OS with no dependencies other than libc. It's still a bunch of files, so for good user experience you would have to ship it as a container (or something like .exe or appimage), but it's really close to Go in terms of size.

https://www.baeldung.com/jlink

Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @06:01AM (#43877983)
It's a configurable property, and Java has a bunch of GCs to begin with.

Also, not using as much memory in these types of GCs is a direct hit to performance. And this actually shows splendidly on GC-heavy applications/benchmarks.

Re:Strings Just Got Faster by concerndc1tizen on Saturday May 03, 2025 @06:22AM (#43878061)
I tried and gave up on getting Keycloak to use less memory. 500-1500 MB for a server with less than 10 concurrent users is ridiculous. And that's even using an external database.
Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @07:28AM (#43878357)
What did you try? As a last attempt you can just check visualvm to see the actual memory use, add a few percent headroom and set that as heap size.
Re:Strings Just Got Faster by neuroelectron on Saturday May 03, 2025 @03:03PM (#43881293)
We were paying a million a month for a custom high performance GC for a little bit but we were able to get off that with a lot of development effort and get our five 9's latency under control.
Re:Strings Just Got Faster by neonsunset on Saturday May 03, 2025 @02:08PM (#43880907)
Much less of a problem in .NET (its GC tuning sits somewhere in between the two, especially when SRV GC + DATAS is in use, like in container scenarios, where Go is funnily unaware of limits set by cgroups and needs an external package to fix it). It does pre-allocate more memory than Go per se but in return yields much, much higher allocation throughput out of box. Java allows for even higher allocation throughput, having multiple more sophisticated GC implementations but as you said is not very good at reducing sustained RSS used by an application.
Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @05:59AM (#43877971)
You need just the right amount of expressivity in a language, so that it is hard to abuse, but still allows writing easy to use libraries.

Java has went over this evolution, implemented generics, lambdas, etc and I believe it strikes a very good balance in not being overly complex (just look at the spec - it's still a very small language, compared to its age, unlike C++ or C#).

Go tried to re-invent this evolution, without having learnt Java's lessons. They will add more and more features until their "simple" will stop applying (though I personally believe that their simple was always just simplistic), simply because you need some expressivity for better libraries, which will later on actually simplify user code.

Also relevant: https://www.tedinski.com/2018/01/30/the-one-ring-problem-abs...

Re:Strings Just Got Faster by SkiFire13 on Saturday May 03, 2025 @02:32AM (#43877252)
> easy to take another class and copy it with small modifications but not mess it up for anyone else (inheritance)

That sounds like a recipe for disaster though, as it generally makes code much harder to read.

Re:Strings Just Got Faster by dgoldstein0 on Saturday May 03, 2025 @03:17AM (#43877399)
Agree, inheritance tends to be overused when programmers try to get too clever. The flatter the class hierarchy the better
Re:Strings Just Got Faster by threeseed on Friday May 02, 2025 @10:48PM (#43876500)
You can use the JVM without needing to use OOP e.g. Scala, Clojure, Python, Javascript, Ruby etc.

Then you can get to benefit from Java's unparalleled ecosystem of enterprise hardened libraries, monitoring etc.

Re:Strings Just Got Faster by neuroelectron on Saturday May 03, 2025 @02:59PM (#43881268)
It's hot really your decision in a corporate environment.
Re:Strings Just Got Faster by SkiFire13 on Saturday May 03, 2025 @02:31AM (#43877249)
Did you actually started to appreciate the same OOP that made class situations impossible to understand or did you gradually switched to a simplier OOP, made up of mostly interfaces and classes that implement them (as opposed to extending other classes)?

In my experience OOP is actually pretty pleasant to work with if you avoid extending classes as much as possible.

> These kinds of niche optimizations are still significant. The OOP model allows them to be implemented with much less fanfare.

If you're referring to the optimization in the article posted then I would argue an OOP model is not needed for it, just having encapsulation is enough.

Re:Strings Just Got Faster by Etheryte on Saturday May 03, 2025 @04:46AM (#43877707)
I'm not sure if the argument that OOP is pleasant so long as you avoid any OOP is a very sturdy one.
Re:Strings Just Got Faster by SkiFire13 on Saturday May 03, 2025 @08:00AM (#43878501)
OOP is the combination of encapsulation, abstraction, inheritance, and polymorphism. Ignoring inheritance does not mean avoiding OOP altogether.
Re:Strings Just Got Faster by Someone on Saturday May 03, 2025 @09:14AM (#43878848)
Also note that the OP said “avoid extending classes”, but didn’t say “avoid implementing interfaces”, so they don’t disallow inheritance in a wide sense of the word.

I think “avoid extending classes” is there because it is as good as impossible to design classes that can be extended easily in ways you do not foresee, and if you do foresee how your classes could be extended, it often is easier for your users if you made your classes more flexible, to start with.

Re:Strings Just Got Faster by hajile on Saturday May 03, 2025 @09:55AM (#43879054)
You can get Encapsulation, abstraction, and polymorphism any number of other ways. Inheritance is the only defining property of OOP.

If you removed all the stuff related to inheritance and trying to fix the leaky abstraction that is objects, the language would be a fraction of the size (compare with Go or StandardML for how small a language without inheritance can be).

Re:Strings Just Got Faster by zelphirkalt on Saturday May 03, 2025 @10:25AM (#43879232)
And as for inheritance: Composition over inheritance. So .... just don't do OOP, I guess?
Re:Strings Just Got Faster by turtles3 on Saturday May 03, 2025 @06:59AM (#43878208)
I'd say that the 'poor man's closures' aspect of OOP - that is, being able to package some context along with behaviour is the most useful part for day to day code. Only occasionally is inheritance of anything other than an interface valuable.

Whether or not this is an endorsement of OOP or a criticism is open to interpretation.

Re:Strings Just Got Faster by _old_dude_ on Saturday May 03, 2025 @06:18AM (#43878047)
OOP is great for libraries but leads to overly complex codes for applications.

For a long time, Java was like, every classes is a library, i do not think it's a failure of OOP, it's a failure of Java.

But I'm optimistic, I choose to see recent additions like records and pattern matching has a step in the right direction.

Re:Strings Just Got Faster by gigatexal on Saturday May 03, 2025 @07:47AM (#43878433)
> Did you actually started to appreciate the same OOP that made class situations impossible to understand or did you gradually switched to a simplier OOP, made up of mostly interfaces and classes that implement them (as opposed to extending other classes)?

My thoughts exactly. Give me more classes with shallower inheritance hierarchies. Here is where I think go’s approach makes sense.

Re:Strings Just Got Faster by neuroelectron on Saturday May 03, 2025 @02:58PM (#43881253)
No. Things only get more complicated with more technical debt. The best you can do is manage it with yet another abstraction.
Re:Strings Just Got Faster by davnicwil on Saturday May 03, 2025 @05:39AM (#43877913)
the mind blowing moment for me with Java came about 5 years into using it, when I encountered the idea - via some smart colleagues - that none of the extra 'stuff' is intrinsic to the language but rather is self-imposed.

Turns out you can write java without the stuff. No getters and setters, no interfaces or dependency injection, no separate application server (just embed one in your jar). No inheritence. Indeed no OOP (just data classes and static methods).

Just simple, c-like code with the amazing ecosystem of libraries and the incredibly fast marvel that is the JVM and (though this is less of a deal now with LLM autocomplete) a simple built in type system that makes the code practically write itself with autocomplete.

It's truly an awesome dev experience if you just have the power / culture to ignore the forces pressuring you to use the 'stuff'.

Re:Strings Just Got Faster by concerndc1tizen on Saturday May 03, 2025 @05:50AM (#43877938)
I love Java in the same way.

But that free-thinking definition of Java clashes with the mainstream beliefs in the Java ecosystem, and you'll get a lot opposition at workplaces.

So I gave up on Java, not because of the language, but because of the people, and the forced culture around it.

Re:Strings Just Got Faster by wood_spirit on Saturday May 03, 2025 @08:09AM (#43878533)
The over engineering creeps in anywhere there is collaboration. It’s not a Java thing, it’s a corporate thing. The new teammate who refactors the perfectly working sql pipeline; the teammate who makes story points a required field on your trouble ticket system, the teammate who just saw a conference talk on rust and wants to apply it etc. Most engineers are not zen masters seeking out simplicity; they are lost with poor grasp of desired business outcomes so they procrastinate by adding complexity and indirection and focusing on tech as if it were the destination not the journey.
Re:Strings Just Got Faster by 90s_dev on Saturday May 03, 2025 @09:34AM (#43878945)
True, but there's also the bored engineers who just can't force themselves to write enterprise code unless they make it fun for themselves. I'm absolutely convinced this is why Clojure even exists and is so widely used in fintech.
Re:Strings Just Got Faster by gorjusborg on Saturday May 03, 2025 @10:15AM (#43879162)
> lost with a poor grasp of desired business outcomes so they procrastinate by adding complexity

I have come to see this as a mix of business people and developers not doing their jobs to protect thier paycheck. Business people, if they want to succeed, need to be converging on a strategy that makes money. Developers need to have a strategy for removing technical barriers to realizing that strategy. The lack of a business strategy often makes an overly general technical platform look attractive.

> focusing on the tech as if it were the destination

So common. Complexity should be considered the enemy, not an old friend.

Re:Strings Just Got Faster by zelphirkalt on Saturday May 03, 2025 @10:22AM (#43879218)
The extreme focus on multiple layers of patterns, where actually a simple function would have sufficed IS a Java ecosystem and culture thing. Just way too many people doing Java, who have never learned another language or ecosystem, let alone paradigm, thinking "I learned Java, Java can do everything, I don't need to learn anything else!" and now feeling they need to solve every problem by applying design patterns mindlessly.
Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @12:47PM (#43880297)
So how do you explain.. every other piece of software written by 5+ people?
Re:Strings Just Got Faster by zelphirkalt on Sunday May 04, 2025 @02:17AM (#43884900)
Well, not by talking about AbstractFactoryProxy, that much is for sure. Rather by talking about which parts of the system are modular and what kind of flexibility the system allows for, what capabilities it has. Nowhere in that picture does a low level implementation detail like an AbstractBlaBlubFooBar enter the the conversation.

There is more to computer programming than the OOP clutter.

Re:Strings Just Got Faster by 90s_dev on Saturday May 03, 2025 @09:32AM (#43878929)
Someone's tweet from about 15 years ago (paraphrased from memory):

"We rewrote 200k line Java codebase in only 50k lines. Guess what language we used?"

The follow-up tweet a day later:

"It was Java."

Re:Strings Just Got Faster by specialist on Saturday May 03, 2025 @11:11AM (#43879584)
> No inheritence.

Yup. Prefer composition over inheritance.

Such a hard sell during the heyday of OOAD. UML, Fusion, RUP, blahblahblah.

Having previous experience with LISP, it just seemed obvious, barely worth mentioning. Definitely set me apart from my colleagues.

FWIW: Our local design pattern study group tackled Arthur J. Riel's Object-Oriented Design Heuristics [1996] https://archive.org/details/objectorientedde0000riel https://www.amazon.com/Object-Oriented-Design-Heuristics-Art... Which might be the earliest published pushback against all that overwrought enterprisey ThoughtWorks-style brainrot.

> No ... dependency injection

Yes and: Mocks (mocking?) is a code stench. Just flip the ownership relationship(s). As Riel, and surely many others, have laboriously explained, to a mostly uncaring world.

Re:Strings Just Got Faster by kazinator on Sunday May 04, 2025 @02:12AM (#43884876)
Prefer inheritance if the first thing you're gonna have to do under composition is to crank out a bunch of delegate methods from the parent object to the contained child, to make the parent substitutable for the child, and the child won't be replaced at run time.
Re:Strings Just Got Faster by specialist on Sunday May 04, 2025 @11:53AM (#43887437)
Probably. I personally haven't done anything like that. Though I'm not sure I follow.

I've mostly done ASTs and (scene) graphs. I prefer dumb objects, stuffing most behavior and logic in an Interpreter (design pattern) implementation. Being a very simple bear, my working memory can't keep track of all the smarts scattered all about.

My current example is processing SQL statements; think expression evaluator (subset) for a very specific use case. I tend to use so called "External" Iterators for walking trees, to keeping all the logic in one place. Versus Visitor, Listeners, or even Active Objects. Which is feasible for this use case, because its bounded and unlikely to change (eg extension points).

YMMV of course. Now I'm just babbling, apologies, and probably went too far off topic.

Re:Strings Just Got Faster by bradhe on Saturday May 03, 2025 @04:34AM (#43877665)
> no work required other than updating the JRE we use

Have you tried updating production usage of a JRE before??

Re:Strings Just Got Faster by microflash on Saturday May 03, 2025 @04:41AM (#43877686)
I 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

Re:Strings Just Got Faster by znpy on Saturday May 03, 2025 @06:54AM (#43878192)
Yes. 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.

Re:Strings Just Got Faster by paulddraper on Saturday May 03, 2025 @12:58PM (#43880394)
The flip side is that for years Java developers have been dealing with suboptimal strings with nothing to do about it.