purego: add benchmarks for calling methods#363
Merged
hajimehoshi merged 8 commits intoebitengine:mainfrom Feb 7, 2026
Merged
Conversation
hajimehoshi
reviewed
Oct 31, 2025
hajimehoshi
reviewed
Oct 31, 2025
Member
|
The benchmark doesn't use C functions. Using C functions in a dynamic library would be more meaningful to test actual cases in the real world. |
Contributor
Author
will extend the callbacks to not be the go no-ops but c calls |
Contributor
Author
|
done. note: this uses long+uintptr because of the bug addressed in #360 |
Contributor
Author
|
rebased/refreshed. |
hajimehoshi
reviewed
Jan 27, 2026
syscall_bench_test.go
Outdated
| // Build C library for benchmarking | ||
| libFileName := filepath.Join(b.TempDir(), "libbenchmark.so") | ||
| if err := buildSharedLib("CC", libFileName, filepath.Join("testdata", "benchmarktest", "benchmark.c")); err != nil { | ||
| b.Skipf("Failed to build C library: %v", err) |
Collaborator
There was a problem hiding this comment.
Shouldn't this be a Fatalf?
TotallyGamerJet
approved these changes
Jan 29, 2026
Collaborator
TotallyGamerJet
left a comment
There was a problem hiding this comment.
Besides the one minor comment this LGTM
Collaborator
|
@hajimehoshi PTAL |
hajimehoshi
reviewed
Feb 2, 2026
syscall_bench_test.go
Outdated
| // Build C library for benchmarking | ||
| libFileName := filepath.Join(b.TempDir(), "libbenchmark.so") | ||
| if err := buildSharedLib("CC", libFileName, filepath.Join("testdata", "benchmarktest", "benchmark.c")); err != nil { | ||
| b.Skipf("Failed to build C library: %v", err) |
Add benchmark tests comparing RegisterFunc, SyscallN, and callback performance across different argument counts (1, 2, 3, 5, 10, 14, 15 args). The benchmarks measure: - RegisterFunc with Go callbacks vs C functions - SyscallN with Go callbacks vs C functions - Round-trip calls (Go → C → Go callback) Includes corresponding C library with sum functions and callback wrappers to enable realistic performance comparisons between different calling approaches in purego.
Replace direct purego.Dlopen/Dlclose calls with load.OpenLibrary/CloseLibrary from the internal load package for consistency with other test code. Includes proper error handling in the defer cleanup function.
Change benchmark callback functions from uintptr to int64 to match C's long type on 64-bit systems. This removes the workaround that was needed for the ARM64 argument corruption bug fixed in ebitengine#360. The args slice remains []uintptr since that's what SyscallN requires.
- Use b.Cleanup for closing library (consistency with file deletion) - Rename Go functions with "go" prefix for naming consistency - Remove unnecessary //go:noinline directives - Remove stale go:generate comment from benchmark.c
- Use b.Fatalf instead of b.Skipf for C library build failure - Panic on unsupported arg count in makeRegisterFunc - Add default panic case to callRegisterFunc
Contributor
Author
|
Resolved pr feedback and rebased to main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add benchmarks comparing SyscallN, RegisterFunc, and callback performance across different argument counts.
This helps measure and compare the overhead of different calling approaches in purego's function invocation system.
Closes #362
Current output: