Live data from Hacker News

Fast software is a discipline, not a purpose

lemire.me

21–30 of 68 posts

Re: Fast software is a discipline, not a purpose

#21
I think of myself as a software craftsman. Just like a master carpenter, the things I make should be not only functional but beautiful as well. Of course we should "care" about our work.

However there are other metrics besides performance that are worth caring about, e.g. readability, maintainability, etc...

Re: Fast software is a discipline, not a purpose

#22
post #7
post #4

Regarding the point "Don’t use floating-point operations when integers will do." I agree that using integer arithmetic can result in cleaner, easier to reason about code when applicable. It then follows that because of these traits the software will faster. But integer arithmetic is not necessarily faster than floating point arithmetic in general; see for example: https://youtu.be/3K2LmnaLLF8?t=31m10s .

> But integer arithmetic is not necessarily faster than floating point arithmetic in general; GPUs was the first place I feel like floats got a much better pathway than any other data type - graphical pixel manipulations also can get away with much higher arithmetic errors, because it's all going to get rounded down to a pixel eventually. On the other hand, the only place where I've really worked heavily with fixed p…

Come on, all reasonable ARM have NEON and VFPv3 (including cortex M) about the only place I saw something that didn't was an old internet router. Hardware completely unsuited to maths.

Softfp does not preclude the use of floating point math at all. It means you pay an extra cost when passing floats as arguments. (Which means you should rather use a hardfp math library if possible.)

Re: Fast software is a discipline, not a purpose

#23
post #9
post #2

“Avoid multiple passes over the data when one would do.” Totally disagree. Unless performance is an issue (like I’m not dealing with a trivial number of elements), I would rather use functional programming approaches to sort data into shape (think map/filter/reduce). These approaches typically result in passing over the data multiple times, and often performing multiple copies, but it makes for readable and less erro…

Performance is always an issue. That said, I fully grant it may be an issue that is worth solving later in the process.

The later you do it, the more expensive it gets. In this it is similar to testing.

Re: Fast software is a discipline, not a purpose

#24
post #2

“Avoid multiple passes over the data when one would do.” Totally disagree. Unless performance is an issue (like I’m not dealing with a trivial number of elements), I would rather use functional programming approaches to sort data into shape (think map/filter/reduce). These approaches typically result in passing over the data multiple times, and often performing multiple copies, but it makes for readable and less erro…

Luckily for haskellers, GHC does a thing called fusion, which is an optimization that pipes together different operations on data, and avoids allocating intermediate results.

(https://www.stackbuilders.com/tutorials/haskell/ghc-optimiza...)

Re: Fast software is a discipline, not a purpose

#25
For most people, "seeing inefficient code" is basically hallucinating. There's real truth to the mantra about premature optimization. I've seen people so many times worry about the performance of something, thinking that some code looks slow, when in actual reality it's a complete nonissue.

Software development is all about compromises, just like any kind of real world engineering. Building a stage for a weekend festival is different from building a bridge over a river. We're always on a budget, so if I can work much faster and safer and lose some marginal efficiency, I'll do it—unless marginal efficiency is what I'm competing on, which it usually isn't.

Re: Fast software is a discipline, not a purpose

#26
1. Make it work

2. Make it right

3. Make it fast

"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%." - Donald Knuth

Re: Fast software is a discipline, not a purpose

#27

Earlier quoted context omitted.

Here it is: https://www.fpcomplete.com/blog/2017/07/iterators-streams-ru...

The key word is "often". Which means not always, which means you cannot rely on it unless you check all your code in Godbolt or equivalent.

Which used to be a common complaint of C and Pascal compilers against manually written Assembly code.

Re: Fast software is a discipline, not a purpose

#28
post #2

“Avoid multiple passes over the data when one would do.” Totally disagree. Unless performance is an issue (like I’m not dealing with a trivial number of elements), I would rather use functional programming approaches to sort data into shape (think map/filter/reduce). These approaches typically result in passing over the data multiple times, and often performing multiple copies, but it makes for readable and less erro…

The vast majority of programming languages return an iterator when you use map, filter, etc. There is usually only one eager evaluation pass at the end that conerts the iterator to a list.

Most languages are capabale of inlining the "next" function of the iterator to generate almost the same code as a regular for loop.

Re: Fast software is a discipline, not a purpose

#29
post #2

“Avoid multiple passes over the data when one would do.” Totally disagree. Unless performance is an issue (like I’m not dealing with a trivial number of elements), I would rather use functional programming approaches to sort data into shape (think map/filter/reduce). These approaches typically result in passing over the data multiple times, and often performing multiple copies, but it makes for readable and less erro…

The advice you quoted is the most valuable of all, in my opinion.

You give "map/filter/reduce" as an example and claim that theses approaches "typically result in passing over the data multiple times". No, since reduce can behave like map and filter, with a proper reduction function you only have to pass over the data once.

> Most collections/array I process have trivial number of elements (That is true for all other advice given in the original article, but not for this: A reduction function only needs one input element and the aggregate/result so far. This function then does not care whether it is called in the context of list or vector iteration, it will happily work with elements read from a stream or any other potentially destructive iterator. The benefit is obvious: Write & debug once, document and never touch the code again until the actual algorithm implemented there changes.

Re: Fast software is a discipline, not a purpose

#30

I think of myself as a software craftsman. Just like a master carpenter, the things I make should be not only functional but beautiful as well. Of course we should "care" about our work. However there are other metrics besides performance that are worth caring about, e.g. readability, maintainability, etc...

Meeting deadlines, getting paid, whether anyone will ever care about the code, again, etc.

I also try to be a 'craftsman', and I try to pick work where that's an option, but I find that in practice, more often than not I have to care about various 'other metrics' at the detriment of craftsmanship.

Although I suppose being skilled at managing these various metrics could in itself be considered craftsmanship. And perhaps that mindset helps a bit with not getting utterly depressed at some of the shit I'm forced to deliver...

Post reply on HN