Reminder: pre-mature optimization #1827
auniverseaway
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Hi Chris, since you copied my code to make your point, let me explain: I changed the code as follows to prevent a CLS from happening. If I don't const stylePromise = new Promise((resolve) => {
loadStyle(`${base}/blocks/mnemonic-list/mnemonic-list.css`, resolve);
});
const loadModule = import('../mnemonic-list/mnemonic-list.js')
.then(({ decorateMnemonicList }) => decorateMnemonicList(foreground));
await Promise.all([stylePromise, loadModule]); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
All of this was covered in Milo Academy, but I want to remind folks:
It's a matter of when not a matter of if Milo becomes a big complicated mess of code that no one wants to work in. In many areas, I could already argue this point. Our mission as a community is to have Milo live as long as possible
It is all of our responsibility to do the work up front that asks, "What benefits am I getting by making this code more complicated?" If you do not know, you should not ship. You could even distill it down more simply: "What benefits am I getting by writing this code?"
Part of what makes Milo performant is knowing at an extremely fine grained level what to load concurrently and what to load linearly. If we were to load everything at the exact same time (promise-based), our scores would drop. If we were to load everything concurrently (await-based) our scores would drop. Being able to truly understand when to use what pattern is what keeps Milo performant while also being as simple as possible. This is why we went through the exercises of forEach vs for loops in Milo Academy.
This is also not just about performance. I recently had an engineer propose adding something to our config object that was only ever going to be used in utils.js. There are specific parts of Milo I would call sacred, and config is one of them. When you add an object into config, that is another property we are blasting to nearly every module on Milo. Every downstream engineer has to say, "This is here, is it important to me?" Pile enough of these up over the years and our config object will balloon with irrelevant properties and it will become more and more brittle.
I will leave everyone with the following example:
vs
Which one is more readable?
Which one is less complicated?
Which one is more performant?
Before you say the second is more performant, can you categorically say this without research? What if the CSS file size is such that it doesn't need to be concurrently loaded? Same for the JS? Did the engineer proposing the second variation do the work to validate this?
Beta Was this translation helpful? Give feedback.
All reactions