Comments (6)
Here's some more info about my benchmark. I updated my original post as well. Environment: Windows 10, Chrome 120.0.6099.200, Yoga 2.0.1. The benchmarks in Firefox have lower times, but the ratio between Yoga execution and getting the computed results is the same, if not worse.
If you guys can double check the results, that would be great. Hopefully there is not something with my environment or configuration that is causing these results.
Benchmark source code:
async function main() {
const yoga = await loadYoga();
postProcessingBenchmark(yoga, 2500);
}
function postProcessingBenchmark(yoga, numChildren) {
const root = createRoot(yoga, numChildren);
let start;
start = performance.now();
root.calculateLayout(10, 10);
console.log("Yoga computation: ", performance.now() - start);
start = performance.now();
postProcessingLoop(root);
console.log("Getting computed values: ", performance.now() - start);
}
function createRoot(yoga, numChildren) {
const root = yoga.Node.create();
root.setWidth(10);
root.setHeight(10);
for (let i = 0; i < numChildren; i += 1) {
const node = yoga.Node.create();
root.insertChild(node, i);
}
return root;
}
function postProcessingLoop(node) {
const result = {
paddingLeft: null, paddingRight: null, paddingTop: null, paddingBottom: null,
marginLeft: null, marginRight: null, marginTop: null, marginBottom: null,
borderLeft: null, borderRight: null, borderTop: null, borderBottom: null,
computedLayout: null
};
result.paddingLeft = node.getComputedPadding(Edge.Left);
result.paddingRight = node.getComputedPadding(Edge.Right);
result.paddingTop = node.getComputedPadding(Edge.Top);
result.paddingBottom = node.getComputedPadding(Edge.Bottom);
result.marginLeft = node.getComputedMargin(Edge.Left);
result.marginRight = node.getComputedMargin(Edge.Right);
result.marginTop = node.getComputedMargin(Edge.Top);
result.marginBottom = node.getComputedMargin(Edge.Bottom);
result.borderLeft = node.getComputedBorder(Edge.Left);
result.borderRight = node.getComputedBorder(Edge.Right);
result.borderTop = node.getComputedBorder(Edge.Top);
result.borderBottom = node.getComputedBorder(Edge.Bottom);
result.computedLayout = node.getComputedLayout();
for (let i = 0; i < node.getChildCount(); i += 1)
postProcessingLoop(node.getChild(i));
}
from yoga.
I read the 'embind' documentation you posted Nick.
From the performance section at the bottom of the page:
The call overhead for simple functions has been measured at about 200 ns. While there is room for further optimisation, so far its performance in real-world applications has proved to be more than acceptable.
This makes perfect sense with what we're seeing. 200ns * 2500 nodes * 13 API calls = 6.5ms. I didn't account for the calls to getChildCount() and getChild() as well while iterating through nodes, so that adds even more time. This doesn't account for all of the time, but it's certainly a ton of overhead.
from yoga.
This seems like a sensible proposal to me. Crossing the WASM boundary is indeed expensive. And in my testing, batching calls helps significantly (esp. in Firefox, which was already faster than Chrome). I have some performance experiments with WASM builds of Taffy and Yoga on this branch DioxusLabs/taffy#394
It's also the case that Chrome's WASM implementation is just generally not very optimised compared to the one in Firefox. So if you're testing in Chrome then there is probably room for optimisation in the WASM-implementation itself.
from yoga.
Wow, that’s a lot of overhead.
One more layer we have in here is “embind”. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html
I’ve been keen on removing it for some unrelated reasons (#1507), but a solution for both of these might be to move the bindings to Emscripten direct function calls. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-direct-function-calls
I think this might lower call/bridging overhead, and the Yoga public API being C should have nice mappings for this most of the time. But I haven’t measured if this has a real impact.
from yoga.
Would you be able to share the code used for the example, where chunkier accessor improved performance?
from yoga.
If you are using Yoga in a case where your source may mutate over time, incremental Yoga layout can avoid the majority of the traversal, both for calculating, and later reading layout results.
But we are missing a trivial binding for the api for this #681
from yoga.
Related Issues (20)
- The typescript definitions link in the standalone documentation is incorrect HOT 2
- Build of v3 with GCC11 fails HOT 3
- Add a CMake option to not build the tests HOT 2
- Add Conan badge HOT 1
- Percentage padding not updated when the parent size changes HOT 4
- Discrepancy between playground and C++ HOT 1
- Where is the operation interface?
- Where is the operation interface? HOT 6
- Top Level Await HOT 9
- Support justifyItems and justifySelf HOT 1
- Incorrect computed height and top value with flex shrink 1 and specific floating point values
- Gap moves children views outside containing view HOT 5
- [Yoga 3] Wrong outcome of max-height percentage value HOT 1
- [Yoga 3] Potential RTL paddingStart/paddingEnd bug HOT 4
- absolute percent position of root element is not correct HOT 3
- YGNodeFree does not mark parent as dirty HOT 1
- Measurement of absolute-positioned nodes
- Box percentage width calculation is different from the Web
- get/setDirection() bindings missing from Yoga npm version 3.0.4 HOT 2
- flexBasis+flexShrink+borderWidth result in an wrong value HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yoga.