Add a Best Practices section to the website. NFC#27334
Conversation
7d2220d to
7052085
Compare
f9da982 to
407b7ab
Compare
dschuff
left a comment
There was a problem hiding this comment.
oops, I forgot to hit send yesterday.
sbc100
left a comment
There was a problem hiding this comment.
Feedback addressed
| - **Don't pass settings that are enabled by default.** To keep command lines | ||
| clean and concise, omit redundant options that are already default in modern | ||
| Emscripten (such as ``-sWASM=1``). | ||
| - **Prefer standard compiler flags** over Emscripten-specifc ones where |
There was a problem hiding this comment.
| - **Prefer standard compiler flags** over Emscripten-specifc ones where | |
| - **Prefer standard compiler flags** over Emscripten-specific ones where |
| files before linking rather than combining everything into a single monolithic | ||
| compiler invocation. | ||
| - **Don't rely on raw ``extern "C"`` pointer manipulation** when interacting | ||
| with complex C++ objects across the JavaScript boundary; prefer Embind. |
There was a problem hiding this comment.
This point feels out of place in this list. It is at minimum debatable, I'd say? Raw pointer manipulation is very simple and efficient once you know it.
Generally speaking, I don't think we should recommend embind so generally, given the overhead. It is better that people make the effort to be efficient where it matters, and use embind where speed isn't an issue, but hard to put that into a short bullet point...
There was a problem hiding this comment.
Maybe "perfer embind, unless you really know what you doing" although I'm not sure how to say that exactly either.
There was a problem hiding this comment.
I think it's best to leave it out. There isn't a simple-enough best practice to recommend.
There was a problem hiding this comment.
I think what I'm trying to do here is have newcomers avoid trying do direct pointer manipulation, and present embind as the well-lit path to getting nice integration between native and JS code.
There was a problem hiding this comment.
My worry is that people start using embind even for simple things that don't need it, and then later ask "wait why is everything so slow?"
I guess I disagree about embind being the well-lit path. Or maybe it is well-lit but has pitfalls 😄
There was a problem hiding this comment.
Could it make sense to have a recommendation based on the type of API being exported to JS? e.g. use Embind if you have a C++ API or you want to do X and Y with your interop, or use something else if it's a C API?
There was a problem hiding this comment.
Perhaps we could phrase it as a warning against direct pointer manipulation unless you have a good reason (and good skills) to go that route.
I'm also thinking if recommending using point + subarray when passing data around rather than using a lot of calls. e.g. prefer getBytesFromWasm(ptr) over a sequence of getSingleValueFromWasm()
I've been working on this as part of the https://developer.chrome.com/docs/modern-web-guidance project and it seems like whatever we do there it makes sense to maintain best practices guide directly in emscripten.