Skip to content

Fix(jit): optimize call_indirect with fast-path type check (#4369)#4613

Open
Harsh-6291 wants to merge 7 commits intoWasmEdge:masterfrom
Harsh-6291:fix/jit-compiler
Open

Fix(jit): optimize call_indirect with fast-path type check (#4369)#4613
Harsh-6291 wants to merge 7 commits intoWasmEdge:masterfrom
Harsh-6291:fix/jit-compiler

Conversation

@Harsh-6291
Copy link

What does this PR do?

  • This PR resolves a significant performance regression in the JIT engine where call_indirect operations were order(s) of magnitude slower than expected.

What are the changes?

  • Modified File: lib/executor/engine/proxy.cpp

Conclusion

  • The performance overhead of call_indirect has been completely eliminated. Indirect calls now have identical performance characteristics to direct calls for intra-module execution.

Closing Issue

bool IsMatch = false;
if (FuncInst->getModule()) {
if (FuncInst->getModule() == ModInst) {
IsMatch = (*ExpDefType.getTypeIndex() == FuncInst->getTypeIndex());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will fail in the case of the type index not the same but type matched.

Copy link
Author

Choose a reason for hiding this comment

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

@q82419 i have made little change now it handle this case

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the comment to clearly describe the reason of this if-statement.

@github-project-automation github-project-automation bot moved this from Triage-required to In progress in WasmEdge Roadmap Feb 4, 2026
@q82419
Copy link
Collaborator

q82419 commented Feb 4, 2026

Since this PR is for the issue about performance, please perf and show the result of difference.

@Harsh-6291
Copy link
Author

hey @q82419 I've verified the performance gains using a benchmark of 10 million iterations. Before these changes, indirect calls were significantly slower, taking about 0.354 seconds due to the repeated structural type matching. With the new optimization enabled, the time for those same 10 million indirect calls dropped to just 0.083 seconds. For comparison, a direct call takes about 0.110 seconds in the same environment, so indirect calls are now effectively as fast as direct ones, successfully eliminating the overhead we were seeing.

if (FuncInst->getModule()) {
// Check if the function type matches the expected type with a two-step
// approach:
// 1. Fast path: If the function instance is in the same module instance, we
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this comment to the if-statement.

} else {
// Independent host module instance case. Matching the composite type
// directly.
IsMatch = AST::TypeMatcher::matchType(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't remove this comment.

@Harsh-6291
Copy link
Author

hey @q82419 i have adjusted the comments

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

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

bug: The call_indirect instruction causes a performance decline in WasmEdge JIT mode

2 participants