Repository navigation
Description
Since #8492 and #8524, compressPage returns early when packedContentEnd proves that the page has no gap. The proof reads every slot of the page (readUnsignedInt for the slot, readNumberAndSize, and the footprint per record) and commit1stPhase runs it on every bucket page the transaction modified or created. So a transaction that only appended a record or overwrote one in place, and left no hole, still pays a walk proportional to the number of records in the page, about 3.9 ns per record in the repro below. For small documents that is the largest single part of the commit.
The repro loads two types of 100,000 records by appends only: Small (a key and two numbers, 1,975 records in a 64 KB page) and Wide (the same plus a 300 character string, 171 records in a page). Each round it times, for each type in turn, 1,000 transactions of UPDATE T SET v = v + 1 WHERE k = :k (the new value has the same size, so no hole) and 2,000 calls of LocalBucket.compressPage(page, false) on one full page of the type, taken into a transaction the way a commit holds it and rolled back afterwards. Both are timed with wall clock and with the calling thread's CPU time. The type order rotates each round.
Results, 7 JVMs per build per JDK, alternating the two builds JVM by JVM, median of the 9 round medians of each JVM, then the median over JVMs, with the min to max over JVMs in brackets. Official 26.10.1 (d36b4ca3ae) and newest main (af4ce03048), -Xms2g -Xmx2g, -Darcadedb.txWalFlush=0 (the default), a container limited to 4 GB and four performance cores of a laptop (5.1 GHz, nothing else timed meanwhile), Temurin 25 with -XX:+UseCompactObjectHeaders and Temurin 21. Microseconds, thread CPU time; wall clock is within 2% to 6% of it.
| JDK | build | type | records in page | compressPage per call |
commit() of one update |
one call / one commit |
|---|---|---|---|---|---|---|
| 25 | d36b4ca3ae |
Small | 1,975 | 7.77 (6.96 to 8.27) | 13.15 (12.61 to 14.12) | 0.58 (0.55 to 0.59) |
| 25 | af4ce03048 |
Small | 1,975 | 7.73 (7.32 to 7.99) | 13.68 (13.12 to 14.61) | 0.56 (0.53 to 0.57) |
| 25 | d36b4ca3ae |
Wide | 171 | 0.75 (0.69 to 0.78) | 7.71 (7.31 to 8.18) | 0.10 (0.09 to 0.10) |
| 25 | af4ce03048 |
Wide | 171 | 0.74 (0.70 to 0.78) | 8.05 (7.81 to 8.62) | 0.09 (0.09 to 0.10) |
| 21 | d36b4ca3ae |
Small | 1,975 | 8.31 (8.19 to 8.51) | 14.68 (14.18 to 17.41) | 0.56 (0.47 to 0.58) |
| 21 | af4ce03048 |
Small | 1,975 | 8.37 (8.16 to 8.44) | 14.99 (14.40 to 16.56) | 0.56 (0.51 to 0.57) |
| 21 | d36b4ca3ae |
Wide | 171 | 0.82 (0.78 to 0.84) | 8.23 (7.81 to 10.13) | 0.10 (0.08 to 0.10) |
| 21 | af4ce03048 |
Wide | 171 | 0.81 (0.77 to 0.84) | 8.68 (8.43 to 10.06) | 0.09 (0.08 to 0.10) |
The two builds do not differ (main over official, per pair, compressPage CPU: 1.00 with 0.96 to 1.05 on JDK 25 and 1.00 with 0.98 to 1.01 on JDK 21, Small). The cost scales with the records in the page, 3.9 to 4.8 ns per record, and for Small it is more than half of the commit.
The same walk inside a larger transaction: the three-statement transaction of a TPC-C new-order (SELECT a Part by key, INSERT an OrderNew, UPDATE the Part, both with UNIQUE_HASH indexes on the key) commits in 17.7 microseconds of CPU out of a 37.6 microsecond transaction on the official build (JDK 25, 7 JVMs). A JFR recording of 100,000 such transactions (JDK 25, 2 ms execution samples, 1,267 CPU samples on af4ce03048, 1,282 on d36b4ca3ae) puts LocalDatabase.commit at 50.4% of all samples (53.6% on d36b4ca3ae), LocalBucket.compressPage at 30.0% (31.5%), and packedContentEnd at 29.1% (30.5%). TransactionIndexContext.commit is 10.6% (11.6%), commit2ndPhase 4.1% (2.9%), and the WAL write 0.8% (0.5%).
Would it work to remember, per modified page in the transaction, whether any write could have left a gap (a delete, a shrinking update, a record moved out of the page), and to skip packedContentEnd for a page with no such mark? The full path would still run for every marked page, so the early return would keep its meaning, and the proof would no longer be paid again at every commit for a page the transaction only appended to or overwrote in place. If the engine already tracks this for the slot merge, that might be enough to reuse.
Code (CompressWalk.java; compile and run with the engine's lib directory on the class path, java -Xms2g -Xmx2g -Darcadedb.txWalFlush=0 -cp 'lib/*:.' CompressWalk /path/to/empty-dir 9 3 1000 2000, which needs an empty target directory on a real filesystem):
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.DatabaseInternal;
import com.arcadedb.database.TransactionContext;
import com.arcadedb.engine.Bucket;
import com.arcadedb.engine.LocalBucket;
import com.arcadedb.engine.MutablePage;
import com.arcadedb.engine.PageId;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.*;
/**
* What the commit pays to prove that a page has no hole, for a transaction that leaves none. Two document types of
* 100,000 records each, loaded by appends only: Small (a key and two numbers, about 1,900 records in a 64 KB page) and
* Wide (the same plus a 300-character string, about 200 records per page). Each has a UNIQUE_HASH index on k. Per round,
* for each type in turn:
* (a) BATCH transactions, each begin(); UPDATE T SET v = v + 1 WHERE k = :k; commit() on a random key (the new value
* has the same size, so the page keeps no hole), timing the commit() call (wall and calling-thread CPU), and
* (b) CALLS calls of LocalBucket.compressPage(page, false) on one full page of the type, taken into a transaction the
* way a commit holds it (getPageToModify) and rolled back afterwards (wall and calling-thread CPU per call).
* The type order rotates each round. The page's record count is read from its first two bytes.
* usage: java CompressWalk DIR ROUNDS WARM BATCH CALLS
*/
public class CompressWalk {
static final int N = 100_000;
static final ThreadMXBean TMX = ManagementFactory.getThreadMXBean();
static double med(double[] v) {
final double[] s = v.clone();
Arrays.sort(s);
return s.length % 2 == 1 ? s[s.length / 2] : (s[s.length / 2 - 1] + s[s.length / 2]) / 2;
}
static String rng(double[] v) {
return String.format("%.2f (%.2f-%.2f)", med(v), Arrays.stream(v).min().orElse(0), Arrays.stream(v).max().orElse(0));
}
public static void main(String[] a) throws Exception {
final String dir = a[0];
final int rounds = Integer.parseInt(a[1]), warm = Integer.parseInt(a[2]), batch = Integer.parseInt(a[3]), calls = Integer.parseInt(a[4]);
if (new File(dir).exists())
throw new IllegalStateException(dir + " exists: start from an empty directory");
final Database db = new DatabaseFactory(dir).create();
final String pad = "x".repeat(300);
final String[] types = { "Small", "Wide" };
for (String t : types) {
db.command("sql", "CREATE DOCUMENT TYPE " + t);
db.command("sql", "CREATE PROPERTY " + t + ".k LONG");
db.command("sql", "CREATE INDEX ON " + t + " (k) UNIQUE_HASH");
db.begin();
for (int k = 0; k < N; k++) {
var d = db.newDocument(t).set("k", (long) k).set("v", 100L).set("w", 1.5);
if (t.equals("Wide"))
d.set("pad", pad);
d.save();
if ((k + 1) % 10_000 == 0) {
db.commit();
db.begin();
}
}
db.commit();
}
System.out.printf("CONF java=%s vm=%s engine=%s rounds=%d warm=%d batch=%d calls=%d%n", System.getProperty("java.version"),
System.getProperty("java.vm.name"), com.arcadedb.Constants.getVersion(), rounds, warm, batch, calls);
final int T = types.length;
final double[][] commitW = new double[T][rounds], commitC = new double[T][rounds], packW = new double[T][rounds], packC = new double[T][rounds];
final int[] records = new int[T];
final Random rnd = new Random(11);
for (int r = 0; r < warm + rounds; r++)
for (int j = 0; j < T; j++) {
final int x = (j + r) % T;
final String t = types[x];
long cw = 0, cc = 0;
for (int b = 0; b < batch; b++) {
db.begin();
db.command("sql", "UPDATE " + t + " SET v = v + 1 WHERE k = :k", Map.of("k", (long) rnd.nextInt(N))).close();
final long w0 = System.nanoTime(), c0 = TMX.getCurrentThreadCpuTime();
db.commit();
cc += TMX.getCurrentThreadCpuTime() - c0;
cw += System.nanoTime() - w0;
}
final LocalBucket bucket = (LocalBucket) db.getSchema().getType(t).getBuckets(false).get(0);
db.begin();
final TransactionContext tx = ((DatabaseInternal) db).getTransaction();
final MutablePage page = tx.getPageToModify(new PageId(db, bucket.getFileId(), 1), bucket.getPageSize(), false);
records[x] = page.readShort(0);
final long w0 = System.nanoTime(), c0 = TMX.getCurrentThreadCpuTime();
for (int c = 0; c < calls; c++)
bucket.compressPage(page, false);
final long pc = TMX.getCurrentThreadCpuTime() - c0, pw = System.nanoTime() - w0;
db.rollback();
if (r >= warm) {
commitW[x][r - warm] = cw / 1e3 / batch;
commitC[x][r - warm] = cc / 1e3 / batch;
packW[x][r - warm] = pw / 1e3 / calls;
packC[x][r - warm] = pc / 1e3 / calls;
}
}
for (int x = 0; x < T; x++) {
final double[] share = new double[rounds];
for (int r = 0; r < rounds; r++)
share[r] = packC[x][r] / commitC[x][r];
System.out.printf("RESULT %-5s records in page %4d | compressPage us per call: wall %s, CPU %s | commit() us: wall %s, CPU %s | one call / one commit (CPU) %.3f (%.3f-%.3f) | %.2f ns per record%n",
types[x], records[x], rng(packW[x]), rng(packC[x]), rng(commitW[x]), rng(commitC[x]), med(share),
Arrays.stream(share).min().orElse(0), Arrays.stream(share).max().orElse(0), med(packC[x]) * 1e3 / records[x]);
}
db.close();
}
}
Activity
test(#9483): pin the packed state after skipped commits, multi-page a…
test(#9483): exercise the commit-time skip itself, compute the size m…
test(#9483): every public page writer withdraws the hole-free shortcu…
docs(#9483): state why a rebased page is always proven and what footp…
perf(#9483): guard the hole-free shortcut under assertions, declare i…
refactor(#9483): keep the packed-write declaration package-private, d…
Merge pull request #9515 from ArcadeData/worktree-arcadedb-9483
lvca commentedon Oct 8, 2026
Fixed in #9515, available in 26.11.1.
You were right: at every commit ArcadeDB walked all the record slots of each modified page to prove the page had no gap left by a delete or a shrinking update, even when the transaction could not have created one.
Now each page remembers how the transaction wrote it. If it only received writes that cannot leave a gap (new records appended, records overwritten with a value of the same size, records grown in place), the check is skipped. Pages touched by a delete or a shrinking update are still compacted exactly as before.
On your
Smallworkload (one same-sizeUPDATEper transaction) the CPU time ofcommit()dropped by about 25% (from ~16.7 to ~12.4 µs). Inserts, edge creation and updates that make a record grow benefit as well. No configuration is needed.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
perf(ArcadeData#9483): skip the commit-time hole proof for bucket pag…
perf(#9483): skip the commit-time hole proof for bucket pages written…
test(#9483): pin the packed state after skipped commits, multi-page a…
test(#9483): exercise the commit-time skip itself, compute the size m…
test(#9483): every public page writer withdraws the hole-free shortcu…
docs(#9483): state why a rebased page is always proven and what footp…
perf(#9483): guard the hole-free shortcut under assertions, declare i…
refactor(#9483): keep the packed-write declaration package-private, d…