Skip to content

Optimize AT state pruning with set-based deletion - #369

Open
ciber592 wants to merge 1 commit into
Qortal:masterfrom
ciber592:perf/prune-at-states-set-based
Open

Optimize AT state pruning with set-based deletion#369
ciber592 wants to merge 1 commit into
Qortal:masterfrom
ciber592:perf/prune-at-states-set-based

Conversation

@ciber592

Copy link
Copy Markdown

Refs #122

Summary

  • replace the per-state pruning loop with one set-based DELETE per block height
  • preserve every state referenced by LatestATStates
  • retain shutdown checks between heights and the existing transaction boundary
  • avoid loading full ATStateData objects and allocating intermediate address/state lists

Previously, pruning one height required two reads followed by one delete statement for every obsolete AT state. The new query lets HSQLDB identify and delete those obsolete rows directly with NOT EXISTS.

Validation

  • mvn -B -DskipJUnitTests=false -Dtest=PruneTests test
    • 2 tests passed, including preservation of the latest AT state and sleeping/finished AT orphaning behavior
  • mvn -B -DskipJUnitTests package
    • build successful on JDK 17
  • git diff --check
    • clean

Performance evidence

A synthetic in-memory HSQLDB benchmark used 48,000 ATStates rows across 1,200 heights and 40 AT addresses, with one latest state preserved per address. Median of three measured runs after warm-up:

Implementation Median prune time Database statements
Existing per-row loop 74.343 ms 50,360
Set-based deletion 32.117 ms 1,200

That is a 2.31x speedup in the synthetic benchmark and a 41.97x reduction in executed database statements. Persistent-node databases should particularly benefit from eliminating per-row delete round trips; the timing is synthetic and is included as directional evidence rather than a production guarantee.

Scope

The change is limited to HSQLDBATRepository.pruneAtStates. No schema, API, or persisted-data-format changes are involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant