How HikariCP’s FastList Outperforms ArrayList for Statement Management

This article examines HikariCP’s FastList, a custom list built on ArrayList that removes range checks and overrides key methods, explaining how these optimizations—such as a faster add operation, a new removeLast method, and unsupported bulk operations—boost the performance of the database connection pool.

Programmer DD
Programmer DD
Programmer DD
How HikariCP’s FastList Outperforms ArrayList for Statement Management

HikariCP is known as the fastest database connection pool middleware, partly because it replaces ArrayList with a custom FastList.

FastList is built on top of ArrayList but removes range checking and overrides many methods to improve performance for managing Statements.

/**
 * Fast list without range checking.
 *
 * @author Brett Wooldridge
 */
public final class FastList<T> extends ArrayList<T> {
    ...
}

Key differences include:

add : overridden to assign directly and only expand when necessary, using left‑shift doubling instead of ArrayList’s 1.5× growth.

get, set, remove(int) : overridden without range checks, assuming valid indices.

removeLast : a new method not present in ArrayList, used to close Statements in LIFO order.

Methods such as toArray, containsAll, addAll, removeAll throw UnsupportedOperationException because they are unnecessary for HikariCP’s use case.

size and isEmpty behave the same as in ArrayList.

Example of the overridden add method:

public boolean add(T element) {
    try {
        elementData[size++] = element;
    } catch (ArrayIndexOutOfBoundsException e) {
        final int oldCapacity = elementData.length;
        final int newCapacity = oldCapacity << 1;
        @SuppressWarnings("unchecked")
        final T[] newElementData = (T[]) Array.newInstance(clazz, newCapacity);
        System.arraycopy(elementData, 0, newElementData, 0, oldCapacity);
        newElementData[size - 1] = element;
        elementData = newElementData;
    }
    return true;
}

The get method simply returns elementData[index] without a range check, and removeLast retrieves and clears the last element:

public T removeLast() {
    T element = elementData[--size];
    elementData[size] = null;
    return element;
}

In summary, FastList is a specialized, high‑performance list tailored for HikariCP’s internal Statement management, sacrificing general‑purpose safety checks to achieve faster execution in its specific scenario.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaperformanceHikariCPFastList
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.