Scrivio Interview library
ConceptFoundations8 min read · updated 12 November 2026

Allocation in a TLAB is just a pointer bump, so why does allocation rate still matter for Java performance?

Allocating one object in a TLAB is cheap, but the memory it takes must be reclaimed later, and young collections run every time eden fills up. So the allocation rate decides how often we pay for a collection, how much memory bandwidth and CPU cache we burn on short-lived data, and how likely a burst is to push objects into the old generation too early.

Why this question is asked

A common argument in code reviews goes like this: the JVM allocates objects with a pointer bump, so allocation is free and we should never worry about it. The first half is true and the conclusion is wrong, and interviewers ask this question to see whether we can tell the cost of one allocation from the cost of an allocation rate. In this answer, we will recap what a TLAB is, follow where the real cost of allocation shows up, look at the cache and promotion effects that people often forget, and then see how to measure allocation before we change any code.

1A Quick Recap of TLAB Allocation

In HotSpot, new objects are created in a part of the heap called eden, which belongs to the young generation. To avoid every thread fighting over one shared pointer, each thread gets its own chunk of eden called a thread-local allocation buffer, or TLAB. Inside its TLAB, a thread allocates by moving a private pointer forward by the size of the object. There is no lock and no atomic instruction, which is why people call it a pointer bump.

So the question is fair: if creating an object costs a handful of instructions, why do performance engineers keep talking about allocation rate, the number of bytes a program allocates per second? The answer is that the pointer bump is only the first and cheapest part of an object's life. The memory has to be zeroed, written, and eventually given back, and that last part is where most of the bill arrives.

2Why Collection Frequency Follows the Allocation Rate

Eden has a fixed size at any given moment. When it is full, the JVM stops the application threads (or, with a concurrent collector, does part of the work alongside them) and runs a young collection. That collection finds the objects in eden that are still reachable, copies them to a survivor space or to the old generation, and then treats the whole of eden as empty again.

Notice what this means. If eden is 1 GB and the service allocates 500 MB per second, a young collection runs about every two seconds. If a change doubles the allocation rate to 1 GB per second, the collections run every second. The collector does not care how cheap each allocation was; it only cares how quickly eden fills. So collection frequency is roughly proportional to allocation rate.

Java
// eden: 1 GB
// allocation rate 500 MB/s -> a young GC about every 2.0 s
// allocation rate 1 GB/s -> a young GC about every 1.0 s
// allocation rate 2 GB/s -> a young GC about every 0.5 s
// each young GC: say 8 ms of pause and some CPU on GC threads
// 2 GB/s -> 2 pauses per second -> 16 ms of every 1000 ms spent paused
Step throughFrom allocation to a young collection
  1. Thread allocates in its TLABpointer bump, a few instructions
  2. TLAB runs outthread asks eden for a new TLAB
  3. Is eden full?
    YesStart a young collectionNoKeep allocating
  4. Copy live objectsto survivor space or old generation
  5. Eden is empty againthe cycle repeats

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

The faster eden fills, the more often the expensive step runs.

The numbers are illustrative, but the shape is real. More collections mean more pauses on the request path and more CPU time spent on GC threads instead of our own code.

3What Each Collection Costs

A young collection's cost depends mostly on how many objects are still alive, not on how many were allocated. Dead objects cost nothing to collect, because the collector never touches them. Live objects must be found, copied and have every reference to them updated. That is why a service that allocates a lot of truly short-lived garbage can still run fine, while a service that allocates a lot of objects that live for a few hundred milliseconds suffers: at the moment of collection, many of them are still reachable and must be copied.

So high allocation hurts twice when objects survive. There are more collections, and each one has more work to do. Each collection also costs CPU, which on a busy container with two or four cores competes directly with request handling.

4The Costs That Never Show Up in a GC Log

Even before any collection, allocation uses memory bandwidth. Fresh memory must be zeroed so that fields start as 0, null or false, and then our constructor writes real values. A service allocating 2 GB per second is writing at least 2 GB per second to memory just to create objects, and on a large machine shared by many JVMs that bandwidth is a limited resource.

There is a quieter cost too. The CPU keeps recently used memory in small, fast caches. Every newly allocated object occupies cache lines, the 64-byte blocks the CPU moves between memory and cache. When we stream through gigabytes of new objects, we keep pushing the data our hot code actually needs, such as a lookup table or a configuration map, out of the caches. The next access to that data then waits for main memory, which can be around a hundred times slower than the first-level cache. None of this appears as GC time, which is why allocation-heavy code can be slow even when the GC log looks healthy.

5Bursts and Premature Promotion

Young collections copy surviving objects into survivor spaces, and objects that survive enough collections move to the old generation. The old generation is collected much less often and more expensively. The design assumes that only long-lived objects reach it.

But there is a catch. During a burst, for example a big batch request or a traffic spike, the allocation rate jumps and collections happen sooner. Objects that would have died a few milliseconds later are still alive at collection time. If the survivor space cannot hold them, the collector promotes them straight into the old generation. This is premature promotion: short-lived data ends up in the long-lived area, the old generation fills faster, and we get more mixed or full collections later, long after the burst is over.

6Measuring Before Optimising

Because allocation cost is indirect, we should measure it rather than guess. There are three common tools, and they answer slightly different questions.

Text
# 1. GC logs: how often young GCs run and how much eden they free
java -Xlog:gc*:file=gc.log:time,uptime -jar app.jar
# 2. JFR: allocation rate and the stack traces that allocate the most
java -XX:StartFlightRecording=duration=60s,filename=rec.jfr -jar app.jar
jfr print --events jdk.ObjectAllocationSample rec.jfr | head
# 3. async-profiler in allocation mode: a flame graph of allocating code
asprof -e alloc -d 30 -f alloc.html <pid>
Which tool answers which question
ToolTells usOverhead
GC logGC frequency, pause times, eden freed per GCvery low
JFR allocation samplesallocation rate, top allocating stacks and classeslow, sampled
async-profiler allocflame graph of bytes allocated per code pathlow, sampled

From the GC log we can work out the allocation rate directly: divide the eden space freed by each young collection by the time between collections. JFR's allocation samples and async-profiler's alloc mode then show which code paths allocate the most bytes, which is the list to work on. Only once we know that a path allocates hundreds of megabytes per second does it make sense to change the code, and then we measure again to confirm the rate dropped.

7Follow-up questions

If allocation is so cheap, should we ever pool small objects to avoid it?

Almost never in ordinary code. A pool keeps objects alive for a long time, so they end up in the old generation, and every write to them that points at a young object adds work for the collector. Pools also add synchronisation and bugs from reused state. It is usually better to reduce allocation by not creating the object at all, for example by avoiding an intermediate list, than to recycle it.

Does escape analysis remove allocation cost?

Sometimes. When the JIT proves that an object never escapes a compiled method, it can replace the object with local variables, which is called scalar replacement. This works well for small, short-lived objects in hot, inlined code, but it is not guaranteed, so we confirm it with an allocation profile rather than assume it.

What allocation rate is too high?

There is no single number. A few hundred megabytes per second is common and fine for many services, while several gigabytes per second usually shows up as frequent collections and CPU spent on GC. The useful test is whether GC time, pause times or tail latency improve when we reduce it.

8Conclusion

In this answer, we saw that the pointer bump makes one allocation cheap but does nothing about what comes after. Eden fills at the allocation rate, so collections happen in proportion to it, and each one costs pause time and CPU, more so when many objects survive. Allocation also spends memory bandwidth and evicts useful data from CPU caches, and bursts can promote short-lived objects into the old generation. We finished by measuring allocation with GC logs, JFR and async-profiler before deciding what to optimise.

What to say in the interviewAbout 90 seconds aloud

Open with

The pointer bump makes a single allocation cheap, but the allocation rate still matters because of what happens afterwards. Eden has a fixed size, so the faster we allocate, the sooner it fills, and a young collection runs every time it does.

Then, if they want more

If I double the allocation rate, I roughly double the number of young collections, and each one costs pause time and CPU on the GC threads. The cost of each collection depends on how many objects are still alive, so allocating lots of medium-lived objects is the worst case: more collections and more copying in each.

There are also costs that do not show in the GC log. New memory has to be zeroed and written, which uses memory bandwidth, and streaming through new objects pushes useful hot data out of the CPU caches.

During bursts, collections come sooner and objects that would have died soon are promoted into the old generation early, which leads to more expensive old-generation work later.

So before optimising, I measure: I read the allocation rate from the GC log or JFR, and I use JFR allocation samples or async-profiler in alloc mode to find the code paths that allocate the most. Then I fix those specific paths and check that GC frequency or latency actually improved.

About this answer

Last updated
12 November 2026
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 "Allocation in a TLAB is just a pointer bump, so why does allocation rate still matter...": https://scrivio-interview-library.netlify.app/java/java-performance/34d0daa638/