Repository navigation
Optimize the code #1042
Replies: 3 comments 22 replies
|
@uninteressant2026 Welcome, Ingo, and a good question – on a C64 you'd have been absolutely right. In JavaScript today it doesn't pay off: the browser compiles this loop to machine code, and a multiply and a divide take a fraction of a nanosecond on a modern CPU. These loops run a few hundred times, so the whole loop costs well under a microsecond, while building one shape takes milliseconds. And here the multiplication is on purpose: Where layerling really spends its time is elsewhere: the boolean operations (cutting holes, grouping), the CAD kernel for fillets and chamfers, and meshes with many triangles. There, the only way to find what's slow is to measure. If you notice something that feels slow in the editor – a shape, a cut, a file – please open a discussion with the steps and a rough time, and I'll profile it. |
|
I have file on a M1 MacBook Pro that takes about 3 minutes 30 seconds to load. It's made up of about 50 basic objects but 30 of them have text elements on them as well. |
|
Layerling became much faster during the recent updates, but it still runs only on one cpu core, as far as I can say. |
Uh oh!
There was an error while loading. Please reload this page.
Hello alltogether,
I'm totally new on github, but many year ago in was programming grafic-software for computers like C64 or Atari Falcon.
That doesn't mean, that I have any clue, what's going on here, but I was always good at optimizing code, to make it go faster.
Especially, because the Computers were very, very slow.
I tock a short glimps at the code of layerling and found a construcion like this:
for (let step = 1; step <= steps; step += 1) {
const angle = (total * step) / steps;
A Division and Multiplication in a loop. For me that's absolutely insane, because it's slow.
In my opinion it would be much faster to do it like this:
let angle1 = total / steps;
let angle = angle1;
for (let step = 1; step <= steps; step += 1) {
angle += angle1;
I know, in this case it has a floating-point-problem, rounding-Errors.
Does it even make sense to look for constructions like this, or is something like this perhaps optimized by the compiler?
Gruß
Ingo
All reactions