Performance tip: If you want to iterate over the keys and values use entrySet()

Overview

Using entrySet() is the fastest way to get all the keys with their values.

Don't use keySet() with get()

From AnimationController.actionPerformed()
for (Part part : map.keySet()) {
    if (map.get(part).isDone()) {
        if (partsToRemove == null) {
            partsToRemove = new ArrayList();
        }
        partsToRemove.add(part);
    }
}
Using get() is much more expensive than Entry.getValue().
for (Map.Entry entry : map.entrySet()) {
    if (entry.getValue().isDone()) {
        if (partsToRemove == null) {
            partsToRemove = new ArrayList();
        }
        partsToRemove.add(entry.getKey());
    }
}

Comments

Popular posts from this blog

Java is Very Fast, If You Don’t Create Many Objects

System wide unique nanosecond timestamps

Comparing Approaches to Durability in Low Latency Messaging Queues