Skip to content

Conversation

jxonas
Copy link
Contributor

@jxonas jxonas commented Oct 9, 2025

Summary

Optimizes storage behavior by skipping persistence when transactions produce no datoms. This avoids unnecessary I/O for empty transactions and operations that add redundant or retract non-existent facts.

Problem

Currently, when a connection is associated with :storage, d/transact! always calls storage/-store, even when the transaction's :tx-data is empty. This happens for:

  • Empty transactions: (d/transact! conn [])
  • Adding redundant facts
  • Retracting non-existent facts

These no-op transactions trigger unnecessary storage writes, impacting performance in scenarios with many such transactions.

Solution

Modified -transact! in src/datascript/conn.cljc to check (seq datoms) before executing storage logic. Storage writes are now skipped when :tx-data is empty.

Key points:

  • No change to transaction semantics
  • TxReport structure remains unchanged
  • Listeners still fire normally
  • Tempid resolution unaffected
  • All existing tests pass

Only call storage -store in transact! when the tx report has non-empty :tx-data.
This avoids unnecessary writes for idempotent/no-effect transactions while preserving
TxReport contents and listener semantics.
@tonsky
Copy link
Owner

tonsky commented Oct 11, 2025

Thanks! Merged and released 1.7.7

@tonsky tonsky closed this Oct 11, 2025
@tonsky
Copy link
Owner

tonsky commented Oct 11, 2025

*1.7.8

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.

2 participants