Skip to content

fix: Add perf tests for escrow create and escrow finish - #7789

Open
TimothyBanks wants to merge 17 commits into
ripple/smart-escrowfrom
smart-escrow/perf-test
Open

fix: Add perf tests for escrow create and escrow finish#7789
TimothyBanks wants to merge 17 commits into
ripple/smart-escrowfrom
smart-escrow/perf-test

Conversation

@TimothyBanks

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Adds very simple perf test around escrow create and escrow finish calls.

Context of Change

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test assertion always fails — see inline comment.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/test/app/Wasm_test.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a look at this

Two correctness issues flagged inline: nanosecond timing is silently truncated to milliseconds by Event::notify (both timing sites in WasmVM.cpp), and the destructor unconditionally prints to stdout for every test instance, not just the perf tests.


Review by ReviewBot 🤖

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/libxrpl/tx/wasm/WasmVM.cpp Outdated
Comment thread src/test/app/TestHostFunctions.h Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One unused variable flagged inline — see line 1588.


Review by ReviewBot 🤖

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/test/app/Wasm_test.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/libxrpl/tx/wasm/WasmVM.cpp Outdated
auto const ret =
vm.check(wasmCode, hfs, funcName, params, createWasmImport(hfs), hfs.getJournal());

hfs.executionTimeEvent("preflightEscrowWasm")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a surprise to me too, but the caller in EscrowCreate.cpp is a mock. So it doesn't have the real impl of executionTimeEvent.

        HostFunctions mock(ctx.j);
        auto const re = preflightEscrowWasm(code, mock, escrowFunctionName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does seem a bit intentional?

@pwang200

Copy link
Copy Markdown
Contributor

This is from claude. I think it makes sense. Please take a look.

The execution-timing metric can't resolve these calls — it reports 0.

runEscrowWasm / preflightEscrowWasm cast the elapsed time to std::chrono::milliseconds before notifying (WasmVM.cpp, the duration_cast<milliseconds> in both hooks), and beast::insight::Event is fixed to millisecond granularity anyway (EventImpl.h: using value_type = std::chrono::milliseconds). The escrow WASM calls run well under 1ms, so every sample truncates to 0.

I measured it locally (Release build, wasmi, kAllHostFunctionsWasmHex, 1000 runs each):

escrow finish (runEscrowWasm):       mean ~88 µs
escrow create (preflightEscrowWasm): mean ~35 µs

That's ~11x and ~28x below the 1ms resolution, and the test output confirms it — both perf cases print Mean (ms): 0.

Comment thread src/test/app/TestHostFunctions.h Outdated
{
if (count > 0)
{
std::cout << "Mean (ms): " << meanMs() << "\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Claude complained see this printed too many times for unrelated tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

As for the resolution of the metrics, the best I can do is fake the values as milliseconds. That is pass in microseconds. StatsD is set at millisecond resolution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude used kAllHostFunctionsWasmHex as the example. As the name says, this wasm code tests all the host functions. I think a fair amount of "normal" wasm code might be less expensive. Assuming claude's measured numbers are real, we will have a lot of wasm executions in the tens of microseconds range. If StatsD's time events in at millisecond resolution, and reporting is not free (google says: "Sending a StatsD metric takes roughly 1 to 5 microseconds of application CPU time.), then we need a different approach. Does it have to be a StatsD time event, or sent every time... I don't know the receiving side to give a good suggestion. On the wasm VM side though, we just want to have some basic statistics, and also get some information if some wasm code takes relatively longer time, like 10 ms.

@TimothyBanks
TimothyBanks requested a review from pwang200 July 22, 2026 19:57

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data race in wasm execution timing — concurrent unordered_map access without synchronization.

Comment thread include/xrpl/tx/wasm/HostFuncImpl.h

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration unit bugs in WASM metrics and test configuration issues - see inline.

Comment thread src/libxrpl/tx/wasm/WasmVM.cpp
Comment thread src/libxrpl/tx/wasm/WasmVM.cpp
Comment thread src/test/app/Wasm_test.cpp
Comment thread src/test/app/TestHostFunctions.h
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@TimothyBanks
TimothyBanks requested a review from a team as a code owner July 28, 2026 17:02
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants