Re:Code optimizations when using async/await
by davidmurdoch on Tuesday January 04, 2022 @10:33AM
(#29795808)
I regularly write code in this optimized form and regularly get code review suggestions to change the code to make it sequential "for readability". Yes, it's harder to read, but it cuts runtime in half or more at the most performance critical part of the application. I think we developers too often try to cater to an imaginary lowest common denominator developer. Sometimes it is okay if code takes a little extra effort to read.
[ Parent
| on HN ]
Re:Code optimizations when using async/await
by happytoexplain on Tuesday January 04, 2022 @10:45AM
(#29795974)
I agree - however, I don't think the developers we are imagining are imaginary. They exist and are common, but we shouldn't be catering to them as much as we sometimes do. Maybe that means leaning away from pragmatism and toward purism, but my hope is that software generally moves that way over time.
Edit: Not "moves that way" as in becomes completely purist, just that I hope it lands a little closer to that side of the spectrum in the future.
Re:Code optimizations when using async/await
by hinkley on Tuesday January 04, 2022 @12:09PM
(#29797077)
Coding for aesthetics is purism. Coding for human cognition/DevEx is pragmatism. They looks similar to an outsider, but the hills they choose for dying can be fairly different.
Re:Code optimizations when using async/await
by lowbloodsugar on Tuesday January 04, 2022 @01:15PM
(#29797951)
Horses for courses. We have to admit that it takes a team with more skill to build a nuclear submarine than it does to inflate a dinghy, but conversely, no point paying nuclear engineers for your dinghy company. If you are building dinghies, or indeed mass producing dinghies for small clients, sure, pragmatism is not using complex async code. If you are building a nuclear submarine, the team better have a real good idea of how these parallel systems interact, don't deadlock the cooling system, and pragmatism might be "who knows TLA+?".
Re:Code optimizations when using async/await
by hinkley on Tuesday January 04, 2022 @12:06PM
(#29797044)
The smaller the function with the perf tweaks, the less pushback you tend to get in reviews. Near as I can surmise, there’s a threshold below which people feel comfortable refactoring code they don’t like the looks of, but the fact of that comfort discourages them from actually doing it.
You do have to watch out for features being added. Plenty of people don’t understand rewording these three lines results in a 10% response time increase.
Re:Code optimizations when using async/await
by darksaints on Tuesday January 04, 2022 @11:22AM
(#29796520)
That can cut both ways. Sometimes optimizations reduce legibility even for advanced programmers, and often for very marginal improvements in performance...or no improvement in performance at all because they're not on the critical path. Sometimes it's okay to make code slower but more obvious as to what it is doing.
Re:Code optimizations when using async/await
by hinkley on Tuesday January 04, 2022 @12:11PM
(#29797105)
Variable hoisting can make a loop faster and the intentions clearer. As long as you don’t hoist the variable entirely off the page, that is. Declaring at the top of a large scope is confusing. I think people got that from older versions of C as I recall. It’s worse than doing nothing.