Skip to content

Native transactions: begin, commit, rollback and is_transaction_active decode a JSON status the caller does not read #225

Open

Description

@tae898

On the native build, begin(), commit(), rollback() and is_transaction_active() each decode a JSON object with json.loads (_native/database.py _tx -> _call) for a status the caller does not read. The reply of arcadedb_n_tx is {"ok":true,"active":..,"depth":..,"commits":..}; begin() and commit() throw all of it away, and is_transaction_active() reads one bool. Each call also goes through five Python frames (begin -> _begin_state -> _tx -> _call -> lib.call).

The bindings discovery pass (untimed, one run, shares are directions and not a speed claim; source: PROFILE-SUMMARY.md of the D-3 path profiles, table generated from it by script) found the native transaction paths mostly Python glue:

path op us (median) crossings per op cProfile Python glue / boundary / json timers: in entry points / Python glue
txn_begin_commit 7.2 4.0 20.3% / 14.2% / 22.2% 41.7% / 58.3%
txn_empty 11.5 6.0 23.5% / 13.8% / 21.3% 39.5% / 60.4%
txn_insert 237.2 8.0 5.5% / 2.7% / 2.5% 92.2% / 7.7%

In the cProfile of txn_begin_commit the top Python frames are lib.call, json.decoder.decode, raw_decode, json.loads and _call, so the status decode is a visible part of the glue. These transaction shapes are on the timed paths of a transactional benchmark harness (explicit begin/commit in l1_tpc and l5, with db.transaction() in l2 writes and e2).

Proposed change (Python only, same crossings, same error texts): decide success, and the active bool, from the text prefix the Java side always writes (ArcadeNative.txState), and decode the JSON only for an error reply and for the callers that read depth or commits (the marks, run_in_transaction). A reply that does not have the expected prefix is decoded as before. Out of scope for this issue: fusing the mark and begin crossings or returning the state as a packed long from a new entry (a Java change, would need an image rebuild); the A/B study decides whether that is worth doing.

The crossing count of every transaction shape is unchanged, and tests/test_native_tx_crossings.py pins it; new tests there pin the decode count per operation. A timed A/B (one-library overlay) is pre-registered before the PR merges.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions