WebAssembly / WebAssembly/tool-conventions
performance issue for std::span on wasm C calling convention
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 372
- Forks
- 75
- PR merge metrics
- No merged PRs in 30d
Description
#include<span>
#include<cstddef>
void baz(::std::size_t *ptr,::std::size_t n) noexcept;
void foo(::std::span<::std::size_t> sp) noexcept
{
baz(sp.data(),sp.size());
}
void bar(::std::size_t *ptr,::std::size_t n) noexcept
{
baz(ptr,n);
}
_Z3fooNSt3__14spanImLm4294967295EEE: # @_Z3fooNSt3__14spanImLm4294967295EEE
.functype _Z3fooNSt3__14spanImLm4294967295EEE (i32) -> ()
# %bb.0:
local.get 0
i32.load 0
local.get 0
i32.load 4
call _Z3bazPmm
# fallthrough-return
end_function
# -- End function
.section .text._Z3barPmm,"",@
.hidden _Z3barPmm # -- Begin function _Z3barPmm
.globl _Z3barPmm
.type _Z3barPmm,@function
_Z3barPmm: # @_Z3barPmm
.functype _Z3barPmm (i32, i32) -> ()
# %bb.0:
local.get 0
local.get 1
call _Z3bazPmm
# fallthrough-return
end_function
std::span is passed by memory, not by registers on wasm. which is extremely slow.
This is going to encourage people to overuse pointers. Please change the calling convention here. Also, the return value has the same issue.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the WebAssembly calling-convention conventions relevant to the C++ std::span example and compare the shown foo and bar assembly. Determine how span parameters and return values should be passed, then document the convention and validate it against generated wasm for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, wasm
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100