« first day (744 days earlier)      last day (4222 days later) » 

12:07 PM
Am I wrong or is the idea that calling a function in a loop 1 million times is slower than calling that function one million times explicitly without a loop extant?
You see a lot tight loop optimizations being unrolling the loop. I just wondered why that is faster than just doing the loop?
 
@TonyTheLion you save the actual loop instructions (jump and test condition, basically), and depending on circumstances, unrolling might enable better scheduling, allowing the compiler to interleave multiple iterations to better utilize CPU resources
but it's rarely going to make a really noticeable difference
 
@jalf hmm right. That seems to match with what I'm just reading. :)
 
on the other hand, unrolling means more instructions, and more instruction cache pressure, so it can slow your code down as well
 
right
it's a delicate balance really
 
yup
 
12:17 PM
that's best left up to the optimizing compiler
 
often :)
 
there are cases where you'll want to do it yourself
but then you're so deep into performance tweaks already that you'll be constantly benchmarking anyway, so you'll know exactly how much (if anything) it buys you
 
makes sense
 
It used to be that saving the loop instructions was the biggest advantage of unrolling, but today, the really big deal is probably scheduling. The CPU can execute 3-4 instructions per cycle, and it is deeply pipelined so as long as the instructions arrive in the right order, adding more instructions costs basically nothing. But if they are not ordered efficiently, you introduce a lot of stalling, so today, I'd expect the interleaving aspect to be a far bigger performance saving
both the compiler and CPU really like long stretches of branch-free code
 
12:23 PM
ah right
 
user1182183
12:43 PM
can anyone link me to a good explaination of L1 L2 and L3 CPU caches? google returns just garbage results
 
user1182183
(and not the wikipedia shit which is always full of 'only expert stuff')
 
sbi
I bet there must be someone out there who can. Does that answer your question, @Gam?
 
@GamErix L1 is faster than L2 but smaller. That's all I know.
That @jalf book has good coverage on CPU caches.
 
it's not complicated, they're just information caches for data from main memory
 
sbi
Nothing is complicated for a puppy.
 
12:52 PM
each L is shared between a different set of cores- L1 is per-core, L2 is two cores, and L3 is four cores, I think
 
There are pitfalls like false sharing that you need to be aware of.
 
and cache stride
cache lines
 
Never heard of cache stride.
 
basically, the cache is implemented associatively
 
sbi
@TonyTheLion Being in the garden on Sunday, I was asked by strangers, over the fence, what the chances are to get a garden in the place where I have mine. (It's not easy in the city to get access to cheap enough land.) I told them the chances are pretty good, currently. So they asked what they should be looking for when evaluating prospective parcels. Fruit trees? Soil? Garden house?
I told them: Look closely at the neighbors. The most beautiful garden will be hell on earth if you can't get along with your neighbors. They were dumbstruck. Apparently, that had never crossed their minds.
 
12:53 PM
like, unordered_map<void*, data>.
 
The term memory hierarchy is used in computer architecture when discussing performance issues in computer architectural design, algorithm predictions, and the lower level programming constructs such as involving locality of reference. A 'memory hierarchy' in computer storage distinguishes each level in the 'hierarchy' by response time. Since response time, complexity, and capacity are related, the levels may also be distinguished by the controlling technology. The many trade-offs in designing for high performance will include the structure of the memory hierarchy, i.e. the size and te...
I found this to be helpful in the past
 
but obviously that would be immensely large for every possible address
so they only look at ... some 16 bits of it
the problem is that if you have lots of addresses that all map to the same cache line
you can blow your cache completely
 
@sbi heheh. You made a good point though.
A CPU cache is a cache used by the central processing unit of a computer to reduce the average time to access memory. The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. As long as most memory accesses are cached memory locations, the average latency of memory accesses will be closer to the cache latency than to the latency of main memory. Overview When the processor needs to read from or write to a location in main memory, it first checks whether a copy of that data is in the cache. If so, the processor immediate...
 
because only one of your N addresses can be loaded at once
 
also this ^
 
sbi
12:58 PM
@kbok That would be called C+-, not C++. You can pretty well evaluate this during the interview, though. Ask them a few things. Are they using the STL? Employing templates? Do they know about exception safety? What did the piece of code look they showed you to assess your knowledge? Full of strcpy() and raw pointers? Remember, the interview is not about them looking down at you to decide. It's for for both of you to check out each other.
I have concluded interviews telling them to not to bother to offer me a job.
 
@sbi Oh, but interviewers are smarter than that. They usually question you about modern C++, and talk about the "nice" part of the code.
Because they want you in, no matter what. The only way to know how it's like when you're in is to ask people who work there.
 
sbi
@kbok Yeah, but if that's the case, they at least know what good code ought to look like, and that they ought to be ashamed for still clinging to all this "other code". Hell, in the C++ job market, that puts them in the upper 20% of the better employers!
 
I have not done too many interviews and I only so far had two jobs.
 
@sbi Still not good enough for my taste :)
 
But IMLE, bad code is in every kind of code base.
 
1:03 PM
I only hire AAA employers.
 
And I do not mean buggy, I mean simply poorly written but correctly written code.
I mean, bad code of its own is not a reason to reject employment, if other aspects are fine.
IMHO :)
It might even be an opportunity to show your skills.
 
Every code is bad in someone's eyes.
I know people who will tell you Java-style C++ code is good because it's easy to understand.
Some people will dismiss any Javascript code because "it's hard".
 
Well, I mean inefficient code doing too many allocations or using bad big-O algorithms when better are available, not using common idioms, inconsistent, with plenty of obvious copy&paste, etc.
 
inefficient doesn't mean bad
 
Yeah, if you're given the opportunity to rewrite/refactor, it's not an issue.
 
1:12 PM
it only means "Wasn't yet optimized"
 
Heh.
"Yet."
IME, the optimization does not happen unless there is some test case that points out the inefficiency.
 
as absolutely should be the case
optimization should be only when it's needed
 
@wilx on the other hand, if you're not able/willing to create that, then the inefficiency obviously can't be a big deal
 
I think that there is a difference between premature optimization and unnecessary pessimization.
 
1:27 PM
I just received advice:
> When a child has a dream and a parent says, "It's not financially feasible; you can't make a living at that; don't do it," we say to the child, run away from home... You must follow your dream. You will never be joyful if you don't. Your dream may change, but you've got to stay after your dreams. You have to.
From a mailing list.
Not sure if excellent or terrible advice.
 
@wilx no one said otherwise. But we're talking about the scenario where the inefficiency exists. It is not "unnecessary pessimization" to leave it as is
but it might well be a premature optimization to spend time and energy optimizing it before you have a test in place to measure (1) if it needs to be optimized, and (2) the actual effect of your optimization
 
user142019
1:47 PM
Hey
 
user142019
The room is dead.
 
long live the room
 
Doing some w**k :((
 
user142019
Some guy wants me to edit my question he downvoted and then he’d undownvote it.
 
user142019
Way too much effort for two rep.
 
user142019
1:52 PM
@MartinJames w**k?
 
user142019
Is that something like wuck?
 
user142019
Ah fuck. I got it wrong.
 
I dare not speak its name - if often offends.
 
user142019
1:53 PM
hahahahahahahahahahahhahahahaa offending people on the internet
 
user142019
what a joke
 
..that which pays..
 
user142019
As my biography on Stack Overflow reads…
 
user142019
> I like offending people, because I think people who get offended should be offended.
 
user142019
Anyway, time to write some software.
 
user425495
1:57 PM
I just watched channel9.msdn.com/posts/C-and-Beyond-2011-Herb-Sutter-Why-C and he talks about keeping data frequently used together close together and separate "hot" and "cold" data (roughly 16 minutes into the video)
 
user425495
Are there any tutorials/books that talk about this kind of optimization
 
user142019
CPU caches data.
 
user425495
Yeah but how exactly do you implement these decisions in code
 
user142019
But for example std::list, which isn’t required to allocate all data near each other, is slow for exactly that reason: lots of cache misses. While std::vector is fucking fast (even with loads of insertions and deletions). Let me find a graph.
 
user425495
He makes it sound as if you have very fine-grained control
 
user425495
1:59 PM
Oh I thought it was something beyond just using appropriate data structures
 
user142019
 
user142019
The green line is a linked list sans allocations, the blue line is a vector with allocations.
 
user142019
@JustinShrake Using appropriate data structures definitely has impact, but only if you use data structures where data is very near together (as is the case with an array).
 
user142019
Try different things, understand how their memory is layed out, and benchmark.
 
user425495
Okay thank you for the clarification
 
user142019
2:03 PM
A linked list is terrible for the cache.
 
Well you can have a linked list with optimized localisation.
 
user142019
That’s true.
 
But if you need that it's stupid to use a list in the first place.
 
user142019
In Haskell, strings are lists of characters. :P
 
Xeo
1
Q: Using values from lambdas in C++ 11

axis#include <iostream> int main(int argc, char* argv[]) { int j; [&](){j = 10;}(); // why I need the last rounded parentheses () and what is their purpose ? // ... return(0); } I get almost everything about how the lambda works, my last question is about why i need the l...

Close votes~
 
user142019
2:10 PM
 
user142019
Also, what a terrible question. Isn’t that just common sense?
 
Xeo
That's what we'd like to think, isn't it?
 
sbi
@kbok The guy who convinced me to work for the company I just started working for I have met at a Scott Meyers seminar. I took that as a pretty good sign that he is interested in good code. (He's now my superior.) It turns out that they, of course, have a lot of smelly code, but first it's not too bad, and second he's open to improvements. So this isn't half as bad as some other jobs I have seen.
 
@kbok but that still perfroms terribly. Just slightly less terrible than a regular linked list
 
user142019
Linked list only perform well if your insert/traverse ratio is 1000000000000000000000000000000000000000000000000000000000000/10.
 
2:14 PM
@sbi Sure. The "open to improvements" is the key here IMO.
 
user142019
“Open to improvements” reminds me of my ex-coworker.
 
I thought you were a student ?
 
user142019
@kbok I had a job during summer.
 
With all your "everything is shit" and stuff
Oh, I see. Congrats, you have now more industry experience than some of your teachers :)
 
sbi
@StackedCrooked That depends on the child's age. Is it 8? => Bad advice. Is it 18? => good advice.
3
 
user142019
2:17 PM
My coworker wrote terrible code. Everything was nicely indented using spaces, he started using tabs (without even converting everything). All code used spaces around certain binary operators, his code didn’t (in the same file). And he wrote a containsOnlyDigits function that returned true for -42.
 
@sbi this
Also there's different possible interpretations of "dream". Is it being a boys band member ? => bad advice. :D
 
user142019
He also rarely committed when he used version control at all.
 
user142019
Stored state in the DOM rather than in a variable.
 
user142019
 
You have to commit to commit.
 
user142019
2:20 PM
$ alias suicide=git
$ suicide commit
 
Shouldn't you store state in the DOM ? It's like, 100x simpler
 
user142019
No. It’s terrible to do that.
 
user142019
Becomes unmaintainable as hell and it’s not simpler.
 
user142019
A variable is much, much simpler.
 
ofc you don't store a variable in the DOM.
 
user142019
2:22 PM
But for example, he did this:
 
user142019
<a href='#'><img src='mute.png'></a>
 
@Zoidberg'-- What about the Jquery data() thing? I'm tempted to use that to store an index of text boxes
 
@Zoidberg'-- So ? It's an image.
 
user142019
1) must be <button>, not <a>. 2) Should use CSS rather than <img> tag. 3) He toggled that mute button by checking if its src attribute was mute.png or unmute.png.
 
@Zoidberg'-- I don't think even IE9 supports <button>
 
user142019
2:23 PM
@Collin it does.
 
user142019
All browsers people still use support <button>.
 
1- not important 2- YAGNI 3-granted
 
user142019
@kbok It is important: semantics.
 
user142019
<a> is an anchor or a link, not a button.
 
user142019
And <img> is for content images, not for buttons.
 
2:25 PM
semantics schmemantics
 
user142019
HTML5!
 
@Zoidberg'-- Interesting.. that's cool. I must have been on the wrong git branch or something when I tried my page out in IE
 
user142019
Search engines look at correct semantics.
 
user142019
And you don’t want that mute button to show up in Google Image Search, either.
 
It depends what it's used for. Also search engines don't care about buttons.
 
user142019
2:27 PM
How’s a search engine gonna know it’s a button or not if it’s an <a> tag?
 
user142019
That is unclear.
 
user142019
Screen readers also perform much better with semantically correct pages.
 
If you're expecting the search engine to work out the fact that there's buttons, there is something wrong with your SEO.
 
user142019
Using an anchor/link for buttons is just wrong.
 
user142019
Buttons are buttons, not anchors/links.
 
2:30 PM
Perhaps he just doesn't know about buttons? They're reasonably new
 
user142019
It’s like using an std::vector with up to one element instead of boost::optional.
 
Besides, what's his doctype?
 
Buttons are form elements, not navigation elements.
 
user142019
Buttons are older than Jesus.
 
@kbok They're controls in the HTML5 sense, it's a good use
@Zoidberg'-- I meant in HTML
 
2:31 PM
Also buttons have a whole different styling method, whereas <a> is simple as fuck. Hell, it's simpler than fuck.
 
user142019
@Collin me too.
 
whoa, it was in HTML4?
 
user142019
@Collin it was introduced in HTML4.
 
user142019
@kbok use a decent reset stylesheet.
 
user142019
(Like you always should.)
 
2:33 PM
shows how little attention I've paid to html over the last few years
 
still CBA
 
user142019
<button>s are not strictly for forms, either.
 
user142019
You can use them wherever you want.
 
@Zoidberg'-- but usually you can't insert elements without first traversing to find the correct position to insert at. Which means that they'll typically still have terrible performance :)
 
But SEMANTICS
 
user142019
2:34 PM
@kbok indeed.
 
user142019
<button> is semantically correct for buttons.
 
user142019
<a> is semantically correct for anchors and hyperlinks.
 
user142019
> The button (<button>) HTML element represents a clickable button.
 
user142019
> The HTML Anchor Element (<a>) defines a hyperlink, the named target destination for a hyperlink, or both.
 
@sbi +1, but I think it's wrong to think of an 18 yo person as a child, because that categorization removes the person's right to self government, so to speak. i don't know the english term.
 
2:41 PM
Hmm
looking at examples, <button> is not an invariant at all
should the "star" action be a button ?
 
user142019
Yes.
 
user142019
But here it’s a span. I don’t know why.
 
What about github's "new repository" ?
 
user142019
Should be an <a> tag.
 
user142019
It’s just a hyperlink.
 
2:42 PM
The "upvote" button ?
 
user142019
<button>
 
@Zoidberg'-- But it's, semantically, a call to action, and it looks like a button
 
So many COOL PEOPLE in here.
 
user142019
Or you can do something like
 
@EtiennedeMartel he he
 
user142019
2:43 PM
<form action='/vote/1337/' method='POST'>
    <input type='submit' name='vote' value='up'>
    <input type='submit' name='vote' value='down'>
</form>
 
user142019
And submit that form using AJAX.
 
user142019
That way it will work when JavaScript is disabled, and it’d still be semantically correct.
 
SO uses links for up/down, favorite, and comment.
 
user142019
Yes, but SO also uses tables for layout. :)
 
err, ... no
 
2:46 PM
SO uses tables? What?
 
user142019
 
user142019
Basically, they have to columns, one with the vote buttons and one with the question body.
 
user142019
You should use tables only for tabular data.
 
meh
You should use tables when they're useful and do the job better than the other tools you have.
 
user142019
s/to/two/
 
2:52 PM
"div class="everyonelovesstackoverflow"" lol
 
Hm, there seems to be a bunch of newcomers this morning.
 
There's a bunch of youngsters who want to learn how to code before the world ends.
 
user142019
LOL Mayan apocalypse.
 
user142019
Two days before my 18th birthday.
 
user142019
Ain’t gonna happen.
 
user142019
2:59 PM
The only thing that will happen is that the world population will be reduced a little bit.
 
@Zoidberg'-- You're a minor?
 

« first day (744 days earlier)      last day (4222 days later) »