Initial problem : I tried to export to wasm different complex structures. Time benchmarks were strange and in linear time for every structure.
So I tried to export vectors of numbers
let mut v = Vec::new();
for i in 0..10000000 {
v.push(6);
}
// export v
0.10 sec
let mut v = Vec::new();
for i in 0..10000000 {
let mut vv = Vec::new();
vv.push(6);
v.push(vv[0]);
}
// export v
0.47 sec
let mut v = Vec::new();
for i in 0..10000000 {
let mut vv = Vec::new();
vv.push(6);
v.push(vv);
}
// export v
0.65 sec
Exporting probably forces wasm to deep copy the exported struct
This test is bad because sizeof(vec) >>>>> sizeof(int)