Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Java's performance model has changed over time: escape analysis, compact strings, better collectors, indy-based string concatenation and virtual threads. Which old performance rules of thumb should your organisation retire, and how do you keep guidance current?

We should retire rules that were true for older JVMs but now cost clarity for no gain: pooling ordinary objects, hand-writing StringBuilder for simple concatenation, avoiding every small allocation, and avoiding thread-per-request because threads were expensive. We keep the reasoning behind them for the cases where it still applies, and we keep guidance current by reviewing it on every LTS upgrade and by requiring measurements for any complexity added in the name of performance.

Why this question is asked

Every engineering organisation carries folklore: rules that someone learned the hard way on Java 6 and that have been repeated in code reviews ever since. Some are still right. Many now make code harder to read and no faster, and a few actively hurt. Interviewers ask this at a principal or architect level to see whether we know how the platform has changed and, more importantly, whether we can run a process that keeps advice honest. In this answer, we will see why rules of thumb age, go through the ones worth retiring and the nuance each keeps, and then set up a way to keep the guide current.

1Why Performance Rules Age

A performance rule of thumb is a shortcut: instead of measuring every time, we remember that X is usually faster than Y. That shortcut was derived from a particular JVM, garbage collector and hardware. When the JIT learns a new optimisation, or the collector changes, or a language feature appears, the measurement that produced the rule is no longer valid, but the rule lives on in style guides and reviewer habits.

Since Java 8 the platform has changed a lot. Escape analysis lets the JIT remove some allocations entirely. Compact strings (JDK 9) store Latin-1 text in one byte per character. String concatenation is compiled to invokedynamic (JDK 9). G1 became the default collector and ZGC became generational and low-pause. Virtual threads arrived in JDK 21, and JDK 24 removed most of the pinning caused by synchronized blocks. Each of these invalidates at least one old rule.

2The Rules Worth Retiring

Rather than a long list, it helps to see the old rule, what changed, and what we say instead side by side. Each row is explained in the paragraphs after the table.

Old rules and what replaces them
Old ruleWhat changedGuidance now
Pool small objectsTLAB allocation, cheap young GCPool only connections, threads, big buffers
Use StringBuilder for a + bIndy string concat since JDK 9Plain +; StringBuilder only in loops
Avoid every allocationEscape analysis, better collectorsOptimise measured hot spots only
Avoid thread-per-requestVirtual threads (JDK 21)Blocking style is fine for I/O-bound code
Avoid synchronizedBetter locks, JDK 24 pinning fixUse the clearest construct, then measure
Hand-tune many GC flagsBetter ergonomics and defaultsPick a collector, set heap size, measure
Each replacement keeps the reason behind the old rule for the cases where it still holds.

Pooling small objects was a reasonable idea when allocation and collection were slow. Today a TLAB allocation is a pointer bump and a young collection costs nothing for dead objects, while a pooled object lives forever in the old generation, needs synchronisation, and risks bugs from state left over by the previous user. So we stop pooling ordinary objects and keep pools for things that are genuinely expensive to create or limited: database connections, threads in a platform pool, large direct buffers.

Hand-written StringBuilder for a + b + c was once faster than the compiler's code. Since JDK 9, javac emits an invokedynamic call that lets the runtime choose an efficient strategy, so plain concatenation is at least as fast and much easier to read. The nuance we keep: concatenating in a loop still creates a new string on every iteration, so building a large string in a loop still calls for a StringBuilder or a joining collector.

Avoiding every small allocation leads to code full of reused mutable holders and manual arrays. For most services, the measured hot spots are a handful of paths that allocate hundreds of megabytes per second; the rest of the code does not matter. So the rule becomes: allocate freely, measure, and optimise the few paths an allocation profile points at.

Avoiding thread-per-request was right when every request held a platform thread with a megabyte of stack while it waited on I/O. With virtual threads, blocking code scales to many thousands of concurrent requests, so simple blocking style is again a good choice for I/O-bound services. We still keep limits on downstream resources such as connection pools, because virtual threads remove the thread limit, not the database limit.

3Rules We Keep, and Why

Retiring folklore should not turn into the opposite folklore. Some rules still hold because the reason behind them still holds. Boxing in hot numeric loops is still expensive, because a Long is still an object. Choosing the right collection, such as ArrayDeque instead of ArrayList.remove(0), still changes complexity classes. Data layout still matters for cache behaviour, and false sharing still exists on every multi-core CPU.

So the best way to phrase guidance is with its reason attached. A rule written as "avoid boxing in numeric loops, because each boxed value is a heap object" can be checked against a new JDK. A rule written as "never use Long" cannot, and it will either be followed blindly or ignored.

4Keeping the Guide Current

The process matters more than any single rule. We make the performance guide a short, owned document, with a named owner such as the platform or JVM team, and we give every rule three things: the reason, the JDK version it was last verified on, and a link to the benchmark or profile that supports it. A rule without evidence is marked as unverified.

Then we tie reviews to the release train. On every LTS adoption, for example moving from 21 to 25, the owner re-runs the small set of JMH benchmarks behind the rules and updates or retires what changed. That is a few days of work every two years, which is cheap compared with the cost of a whole organisation writing worse code for a decade.

Finally, we change the default in code review. Performance-motivated complexity, such as a custom cache, a pool, manual inlining or unusual data structures, must come with a measurement: a JMH result, a profile, or a production metric showing the problem. Simple code needs no justification. This flips the burden of proof, so outdated rules stop creeping back in through reviews.

Step throughA rule's life in the performance guide
  1. Someone proposes a rulewith the reason and a benchmark
  2. Owner records itwith the JDK version it was verified on
  3. Next LTS upgradere-run the benchmarks behind each rule
  4. Does the evidence still hold?
    YesKeep it, update the versionNoRetire it or rewrite the guidance
  5. Review checks new complexitymeasurement required, simple code is the default

5 steps in order. Play them, or step through them one at a time.

Rules carry their evidence, so they can be re-checked instead of repeated.

5Follow-up questions

How do you convince senior engineers who rely on these rules?

With their own tools. Run a small JMH benchmark of the old pattern and the simple version on the current JDK, show the numbers in the guild meeting, and show the profile of a real service where the hot spots are. People let go of a rule more easily when they see the measurement than when they are told it is outdated.

Is object pooling ever right in application code?

Yes, when creating the object is genuinely expensive or the resource is limited: connections, large direct ByteBuffers, objects with expensive native setup, or a low-latency system that deliberately keeps allocation near zero in a hot path and has measured it. The rule is about ordinary small objects.

Do virtual threads make reactive code obsolete?

Not entirely. They remove the main reason many teams chose reactive style, scalability of blocking I/O, so for typical request-response services blocking code on virtual threads is simpler. Reactive libraries still fit streaming with backpressure or when a team already has a working reactive stack.

6Conclusion

In this answer, we saw that performance rules of thumb are shortcuts tied to a JVM generation, and many have aged badly: pooling small objects, hand-written StringBuilder for simple concatenation, avoiding every allocation and avoiding thread-per-request. We kept the reasons that still apply, such as StringBuilder in loops and pools for real resources. To keep guidance current, we gave each rule an owner, a reason and evidence, re-verified it on every LTS, and required measurements for performance-motivated complexity in review.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by saying that most performance folklore was correct for the JVM it was measured on, and the platform has moved a lot since then. The rules I would retire first: pooling ordinary small objects, because allocation is a TLAB pointer bump and dead objects cost nothing to collect, while pooled objects live in the old generation and bring synchronisation and state bugs; we keep pools only for real resources like connections.

Then, if they want more

Hand-writing StringBuilder for simple concatenation, because since JDK 9 javac compiles it to invokedynamic and the runtime picks a good strategy, though building strings in a loop still wants a StringBuilder. Avoiding every small allocation, because escape analysis and modern collectors make most of it free, so we optimise only what an allocation profile shows.

And avoiding thread-per-request for blocking I/O, because virtual threads make that style scale again. To keep the guidance current, I would make the performance guide a small owned document where every rule has its reason, the JDK version it was verified on and a benchmark. On each LTS upgrade the owner re-runs those benchmarks and retires what no longer holds.

And in code review, any complexity added for performance needs a measurement, while simple code needs none.

About this answer

Last updated
12 November 2026
Versions it names
Java 9, Java 21, Java 24, Java 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Java's performance model has changed over time: escape analysis, compact strings, better...": https://scrivio-interview-library.netlify.app/java/java-performance/81795ca057/