This is article is a bit different from what we normally post, so be sure to give your opinion in the comments if you want to see more of this (or not). You will most often find these types of software development rants on a programmer's personal blog, but I find them interesting so here we go.
There are two camps in software development regarding optimization, each with diehard advocates. One side argues for software to be strictly designed, with decisions needing to be coherent and performance-minded. The other viewpoint claims that optimization should be done after profiling, because you could spend weeks making a fairly useless chunk of code purr like a kitten, and ignore the turkey that's using 99.99% of your resources.
Both sides can also point to situations that validate their opinion. The latter, “don't premature optimize” crowd can show examples where time is wasted because the engineer didn't look before they leaped. One such story comes from Chandler Carruth of Google. One of his first tasks at the company was to review code from Ken Thompson, a “very senior engineer” who created Unix and defined UTF-8. It solved rule-matching with about a 20-fold increase in performance over what they were currently using. When Chandler went to integrate the fix, his colleague mentioned “Yeah, turns out our use-case overwhelmingly hits a single rule, so I just check it first. It's now 100x faster.”
The other crowd says that, even if you can find exactly where poop stinks, you're still polishing a turd. One issue that is commonly pointed to is garbage collection. In memory-managed languages, this process scans through your application to delete unused chunks. Its goal is to remove memory leaks without users needing to carefully manage allocation themselves. The problem is that it necessarily freezes basically every thread and often takes several frames worth of time to complete. As such, you can either live with the bad user experience in real-time applications, or you can carefully design your application to avoid leaking memory. If you take the time to design and architect, it allows you to either choose a framework without garbage collection, or sometimes reduce / eliminate how often it triggers.
So the argument is over-thinking wasting time versus under-planning painting software into corners. As it should be somewhat obvious, both are correct. It's a bad idea to blindly charge into development, and it's good to think about the consequences of what you're doing. At the same time, what you think means nothing if it differs from what you measure, so you need to back up your thoughts with experimentation.
The challenge is to coast the middle for the benefits of both, without falling into the traps on either side.
More of this content, please
More of this content, please 🙂
I’m not game developer, but as long time developer and architect of enterprise software systems, I’d say balance is required between those two points of view.
Donald Knuth’s “premature optimization is root of all evil” is misunderstood by many that don’t design for performance. Design is just as important as optimizations later.
Design for performance, then trace and measure, measure some more and finally optimize parts that make sense.
Thanks!
Thanks!
So what is it actually
So what is it actually supposed to be? I mean as a format. It’s a “bit” too short to describe what the problem is. If I would not know about the topic in advance I would probably not understand what all of that is supposed to mean for software development, especially software which takes 3+ years to make, and then to support, and update it.
I definitely would not mind some more “insider” information about what’s going on behind the scene in different companies, but I think there should be a bit more… more. Something that would help me and others to understand why something is a problem if it is a problem, and who and how approaches it.
It’s more intended to be kind
It’s more intended to be kind of theory rather than anything specific.
Personally, I don’t mind this stuff but this site might not have an audience that could really appreciate it.
That’s what I’m not sure of.
That's what I'm not sure of. We'll see (how people comment, number of views, who links it, etc.).
Thanks for the feedback! I’ll
Thanks for the feedback! I'll definitely keep this in mind for future articles (if I do more of these).
I find these type of topics
I find these type of topics interesting, but I tend to look for them in other, maybe more appropriate places. I think, just my opinion, software/coding topics fit well for pcper if they can illustrate some use case of recent hardware, like SIMD, AVX, FPGA, memory compression, tessellation, variable types and bit depth, MSAA, etc. I think there are plenty of cases where hardware meets software which will be interesting for the readership. I’m sorry if my imagination/vision of the pcper readership, based on no facts what so ever, is not in line with reality.
Thanks! Don’t be afraid of
Thanks! Don't be afraid of how accurate your "imagination of pcper readership" is, because it shouldn't even be a "right or wrong" thing. Your input is definitely appreciated. It's my job to interpret it, and use it to guide future trials, which are re-tested.
Problem with a lot of
Problem with a lot of development , especially business software is you can’t predict or exactly get an accurate picture of what the client wants. You think you do until you’re underway.
Normally a level of prototyping is involved, user interaction then defines and shapes the finished product.
So you can design that won’t change right from the start, but other things crop up mid way through and that’s where some of the performance can drop off.
Time is money so if something is deemed fast enough then as long as its not totally inefficient its probably adequate until further load etc proves it otherwise.
nice article XD! while this
nice article XD! while this topic doesnt necessarily adhere to the ‘hardware’ focus of pcper, it still never the less applies imo. especially if you consider how much of a role software optimization plays in some types of hardware. gpus for instance.
i think the idea of articles like these, not finding an audience here, is a little presumptuous. while i agree, its not as casual and easy to digest as a fps graph, its much more appealing than a general press release. which, unfortunately, through the fault of no one, are what predominate the front pages of tech websites, not just the Per, during the lulls between major hardware releases. i think a lot of regular readers would prefer to read something like this, as opposed to a post about a new case from corsair.at the end of the day, regardless of relevancy to the site or reader comprehension, what matters most is genuineness. and that came across here imo. just as it does in other posts here at the Per for that matter. i dont think hellstrom was trying to push hardwest on the pcper readers the other day for instance. no. i honestly feel he was a) excited about the game and b) felt pcper readers should check it out. thats all. i think you’ll find that, whether you like it or not, even casual readers/listeners to pcper begin to develop general ideas of what the staff is like. and insight or confirmation of those ideas, are only going to be well received imo. digital campfire of shared experience. go ahead and run with that one. that’s what you guys have and should foster. you can do gpu reviews in your sleep by now. just my 2sense…administer with a healthy dose of angry moba player.
as far as the topic of the article itself, i get the suspicion that what you’re proposing here, is very much ‘insider baseball’. and perhaps something that is just too over my head, for me to presume to offer an opinion. i feel like im missing a few more key aspects of software development in general, because it seems fairly straightforward, that identifying the problem is inherent to the process of ‘optimization’, regardless of industry/application. so the fact that there are two sides to this particular issue in coding, just tells me im obviously missing something. the ‘polishing a turd’ comment makes it sound that the performance-minded would be more concerned with rebuilding than mere renovation, if it ever came to that point. if thats the case, then perhaps that’s a better way to frame the issue. it makes me see the performance minded as taking the whole notion of ‘luck favors the prepared’ in the initial design very much to heart, whereas the other side adopts more of a ‘lets just throw it against the wall, and see what sticks’ approach and feels time/energy can be better used on analyzing said wall. if im understanding it correctly, then yes. the challenge does indeed lie in leveraging the benefits of both, while simultaneously mitigating the risks. im sure a lot of ‘i told you so!’ conversations have been had… XD! but im probably missing someting 🙂
I would argue that a good
I would argue that a good developer do both.
a) spend the time to design a solid algorithm
b) profile to optimize only the part that need optimizing
why? because profiling is ‘free’…
and, unicode codepoint encoding is an example of a bad design.
utf8, utf16, utf32.. wtf I say
Whats wrong with dedicated
Whats wrong with dedicated 8-bit, 16-bit, and 32-bit types? I still work on 8-bit CPUs, typically as really cheap co-processors, and having UTF-8 support is a godsend.
Secondly, time = money, and neither are unlimited. We write the best code time allows us to. Simple as that.
Nothing is wrong with
Nothing is wrong with compression…
But utf8 is badly designed, its not space efficient and its not compute efficient.
utf32 is just wasteful. it can encode 4 billion codepoint, the unicode spec is limited to under 1.2 million
utf16 is not completely borked, but the encoding is still not efficient to manage. (in part because unicode itself was not designed thinking forward, but was reactionary, the point of this discussion…)
Time? this is exactly my point. Time is key, that is why you dont optimize code ahead of time.. profiling is ‘free’ (times wise) .
So you dont optimize code before can measure the effort vs benefts. Because you have a limited time budget, the profiler will allow you to sort you work in term of higher return on investment.
Saying that there are
Saying that there are performance issues with other parts of the code is not an excuse for a programmer to write bad code under any circumstance. Moreover, in the future, if the code he writes will be sent towards optimizing then effectively 2 people waste time on the same issue.
Profiling should be done regardless to assure better operation of the software. Although I agree with the fact that a huge amount of resources should not be spent on parts of the code that are not performance critical, this should not give a green light for doing the worst job possible. The solution, is neither in my opinion, but a reasonable amount of both, give that most consumer grade software passes through profiling stage.
You do program-level
You do program-level optimizations later, but you make sure your code blocks and sub-CSCI’s aren’t running like total slugs during the design phase. Vectorcast is a godsend in that regard.
This isn’t the right place
This isn’t the right place for this sort of content. There likely aren’t enough actual experienced programmers to actually comment on the content meaningfully. Rather than trying to talk to programmers however explaining programming to educate the audience could work since so much of what hardware(and software) does is dependent on how the code is written and its the singly most overlooked aspect of things like game and GPU performance reviews.
As to the topic at hand. The problem in this case depends on your software and its lifecycle. In a typical business the main problem is understanding the problem itself and what a decent solution for it is. Thus most of the time the best thing to do is have clean code that follows the business intent making it easy to change, optimisation becomes a secondary task only when something is actually too slow. Whereas if you are making a video encoder you should design around performance and weaving it into everything you do because the intent of the software is clear and the lifecycle for updates is more constrained. Thus the two different approaches (and a mix inbetween) mostly get chosen by default on the projects context. An experienced developer will choose which of these they pursue dependent on the work at hand, I have both developed with performance in mind from the outset as well as programmed to make the intent of the code as clear as possible. Depends on the context of the project and if the requirements came with hard performance targets to begin with.
Please don’t write any more
Please don’t write any more articles/posts/whatever you call this. The four paragraphs that you wrote mischaracterized the topic that you were trying writing about. You would be better of just linking to blogs of people like Chandler Carruth or Bjarne Stroustrup.
If you honestly believe the summary of the two sides of the argument is “So the argument is over-thinking wasting time versus under-planning painting software into corners” then please actually read the arguments. The don’t optimize early camp is all for doing design, even for performance, up front. They just don’t believe in trying to spend “too” much time designing a specific chuck of code for performance if it isn’t clear that that chunk of code will be the bottleneck.
If the readers of this site want an actual discussion of part of this topic then read the following paper, not four paragraph of drivel. The short summary is that they re-wrote a benchmark focusing on good design instead of performance with the results including a more performant program.
http://www.stroustrup.com/improving_garcia_stroustrup_2015.pdf (http://www.stroustrup.com/papers.html)
This site should spent time writing articles about things in your wheelhouse (hardware reviews), not butchering topics that other people handle better.
to the folks saying there
to the folks saying there isnt audience here , or the audience wont understand… 1) the fact you’re posting contradicts your statement and 2) really? lol. ‘programmers’ are the only people in the world that can understand this? rofl. so cute. so precious
and SM did NOT butcher the topic. clearly. you guys understood it fine. as did most of the other “non-programmers”.
question for all the skeptics here…. what was pcpers most successful story/piece of the last few years? the whole multi-gpu stuttering issue right? not only is that NOT a hardware specific issue, it also deals precisely with this particular topic. but nah, this is something the pcpers readers are too dumb to figure out, let alone a topic with which pcper should concern themselves.
it doesnt appear that some of the reasons being given to the contrary, have much basis in reality. opinion is opinion, granted. but when the evidence provided is fallacious, let alone contradictory, it doesnt bode well for the cause. pcper may very well not be well advised to not continue this type of article, but not for the reasons provided thus far. sorry
a lot of these reasons sound more like fear of change than anything else. and it wouldn’t even be changing anything. just throwing some ‘intellectual’ spice into the everyday monotony that comes with the territory in running this type of site. there are only so many pieces of kit that can be released, and subsequently reviewed, in a given time period. filling up that time with other forms of engagement, is only logical. and again, to argue that this topic of ‘software optimization’, does not have any correlation to hardware, is quite frankly absurd, and speaks volumes.
Today we have (only) one
Today we have (only) one problem (cause of other problems) – awfully powerful computers. Why to think about efficient algorithms and very efficient programming when there is N GB of RAM and N GHz with N cores to run. Even embedded today is running Linux on 32 bit ARMs with a lot of memory. Take a look at IoT. Ridiculous!
I remember days when programming in Basic was unprofessional and today is normal to use Python, JavaScript, etc. 99.9999999999% of people are not aware what quad core at 2GHz means! Take a look at UWP – universal windows platform. Almost programming by drawing for anyone. Result will be much disasterous applications killing hardware. But hey, tomorrow we will have 16 64 bits cores running at 4GHz and 10Ah batteries in phones.
My 5 cents. Some 25 years ago I rewrote Clipper app in C++ with my own database version and we got 1000 times increase in speed.
good point. not sure if it
good point. not sure if it applies in this scenario, but the logic is sound and i like it. it reminds me of cars back in the day tbh. they were not too terribly concerned with gas mileage, mainly because drivers could retain petroleum for so little. it wasn’t until oil began to become more scarce (ie expensive), that ‘gas efficiency’ became a thing.
CPUs haven’t gotten
CPUs haven’t gotten appreciably faster in 5 years, and GPUs are hitting the wall too, so the future might be to go back to optimizing software and figuring out new ways to solve problems in more efficient ways, which goes back to the article at hand. Efficient designs and optimization are both important. The demand to get more done while consuming less power to get more battery life out of portables (and lower cost from smaller batteries) will demand even more efficient software. Server software is also demanding higher efficiency as demand scales up.
I would say we’re definitely not in an era of software development stagnation or disinterest in efficiency. Pretty much just games where they make back their investment within a week with little reason for continued support.
As software developer, I will
As software developer, I will say more content like this please as well.
I would enjoy more content
I would enjoy more content like this