There is a memory optimization that can be used in Vert.x in several places.
For example, here:
io.vertx.core.impl.VertxImpl.InternalTimerHandler
private final AtomicBoolean disposed = new AtomicBoolean();
AtomicBoolean is quite a heavy object (many times bigger than volatile boolean)
It can be replaced with VarHandle. The VarHandle has all the same operations, but it is a static field member of a class and in object there is only a volatile byte or int field. You can see this technic in JDK
java.util.concurrent.FutureTask#set
Replacing Atomic* with VarHandle and volatile in libraries makes sense.
It dramatically reduces the memory footprint without disadvantages.
I could make a PR for InternalTimerHandler.
There is a memory optimization that can be used in Vert.x in several places.
For example, here:
io.vertx.core.impl.VertxImpl.InternalTimerHandlerprivate final AtomicBoolean disposed = new AtomicBoolean();AtomicBooleanis quite a heavy object (many times bigger than volatile boolean)It can be replaced with
VarHandle. TheVarHandlehas all the same operations, but it is a static field member of a class and in object there is only a volatile byte or int field. You can see this technic in JDKjava.util.concurrent.FutureTask#setReplacing
Atomic* withVarHandleandvolatilein libraries makes sense.It dramatically reduces the memory footprint without disadvantages.
I could make a PR for InternalTimerHandler.