Skip to content

u/MagicBobert

In this archive from Dec 2010 to May 2015

4
posts
129
comments
2
media
518
score

Top posts

Top comments

I don't completely disagree with him. Story time.

I was writing a ray tracer a couple years back and had fleshed out a decent vector class. I used good software engineering principles, adding getters and setters to the x/y/z/w components of the vector. I couldn't for the life of me imagine ever adding anything to them, but hey, that's what the software engineering dogma said to do, so I did it.

When I was nearly finished I decided to do some profiling to see if there were any obvious hot spots I could improve. The usual suspects showed up near the top (intersection testing against the acceleration structure, etc.), but some of the most unexpected (and disturbing) contenders were my vector accessors. They weren't the top offender, but why on earth were they taking up any noticeable share of CPU time?

Well, the fact is that in a ray tracer, those vector accessors are going to get hit a lot. By a lot, I mean that in a reasonably sized scene you're going to see millions, billions, possibly even trillions of calls to your vector accessors. They're used for points, rays, colors, and a whole host of other things.

Thankfully the fix was trivial. I marked the accessors inline and the function call overhead completely disappeared from the profiling results and I got a noticeable (10-20%) speedup.

The moral of this story? Following the software engineering dogma is not always the right thing to do. The best programmers know the rules and follow them most of the time, but know when it's right to break them and are not afraid to do so.

TL;DR:
Accessor functions have a cost. They are not free, in programmer-time or execution-time. Rather than always adding them blindly, think about whether or not you might reasonably need them in the future, and how many times they might be called. No reason to pay function call overhead for something you don't need. They're also always worth questioning for POD types, since the common usage patterns for them are usually different from instantiated classes.

25 points

No, no no!

Multithreading using a dataflow model is very bad in software. It works great in hardware (CPUs, GPUs) because they're designed as synchronous machines driven by a single clock with virtually no communication cost between stages of the pipeline. These assumptions do not hold true for software.

First, the communication cost between stages in the pipeline is expensive, and it's multiplied by the number of stages in the pipeline and the number of objects being pushed though it. Suddenly communication costs become a huge part of what you're doing. That's time you could be spending doing useful work.

Secondly, it doesn't scale. Your parallelism is permanently fixed at the number of stages you designed into your pipeline. The ideal case is when the processor has exactly the same number of cores as stages in the pipeline. If you have more cores, they're unused and wasted, if you have fewer cores, you have to context switch between them. If you want your software to scale as new chips roll off the assembly line, you can't use a model that has a fixed number of threads.

Lastly, pipelines increase bandwidth at the cost of increased latency. You are pushing out more work per unit of time, but the overall time from beginning work to finishing it is increased as well. Real-time applications typically suffer from increases in latency.

19 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.