Especially relevant to this community...

Especially relevant to this community…

Originally shared by Daniel Garcia

Why do I spend so much time trying to optimize the libraries that I make available for other people to use?

Or to put in a more general way, why is timing and optimizing code important? Well - here’s an example. Someone was using a graphics library to do some simple animation. This animation consisted of a filled rectangle and a pair of filled circles in each frame. The original graphics library code they were using would take 175ms per frame to do these filled circles and rectangles. That’s only 6 frames/second, and that’s not including the time that it takes to push data out over SPI to the oled display they were using. (Which, by the way was being done with bitbanging, and the only attempt at spi support out there isn’t bad, but is also not optimal - but for once, i’m not ranting about bit banging vs. hardware output).

Getting the timing down to 31ms helped them a fair bit. However, that still would cap them at 32 frames per second if they were doing nothing else (remember above comments about data writing, however, also, who wants to just push frames?).

Getting the timing down to 2.25ms/frame, however? Well - hell, that’s over 440 frames/second. Sure, it’s rare you’d want to run something that fast, so let’s look at this another way. Previously, spending 100% of their time drawing each frame, and not even pushing the data out, they could only have 5.6fps. Now, they can have smooth, 30fps animation and still have 93% of their cpu time available to do other things!

Whether it’s more interaction, more complex animations, maybe going to 60fps and using interpolation to smooth things further.

Now, why is it extra important to think about these things when you’re publishing libraries for other people to use especially in the arts and maker communities[1]? Because many people don’t know how to dig in or optimize. In fact, in some cases, it doesn’t even occur to them that they could. They just end up assuming that “I guess arduino is just slow!” It discourages them from that thing they were excited about doing. It may even end up stopping them from that thing they were doing. Or maybe they don’t get it done in time for maker faire. Or maybe they just set their sights lower.

Of course, many times people doing the libraries themselves don’t know that optimization is needed, or possible, or how to do it. Not everyone knows everything - that’s part of what keeps the world and people interested. So, instead of just ranting about it, instead, of devolving into complaining about some library’s code, instead of making fun of said code, instead of any of that, i’m going to put my code and skills where my mouth is.

Which is to say, i’m coming for your libraries. Your misspent clock cycles have nowhere to hide, your excessive memory usage is about to be deflated. The pull requests are coming.

This is going to be fun >:)

[1] I call those out specifically because that was the situation that inspired this post. However, this also goes for really anything that is available to use publicly. Activist related systems, for example - if they’re slow, people will be less likely/able to use them, or worse, they may not be able to handle a load spike in a time of need.