News for hackers. Stuff that matters.
Re:Why we didn't use a bloom filter by TeMPOraL on Saturday March 17, 2012 @03:31AM (#3716590)
"Have you ever used the STL? I did for about 6 months professionally, and I'm glad that I could go back to C and Python. More seriously, object orientation in C++ doesn't come for free. Aside from the pain of the syntax of using C++ templates (and difficult to parse error messages), all of that object orientation hides the complexity of method dispatch in what are known as vtables. If your system has to call them to dispatch, you are wasting time in that processing when you could be doing something else."

This fragment made me WTF, so either I missed something in the C++ development of last few years, or...

a) How can you make standard-OOP-like method dispatch faster than vtables?

b) Since when STL uses so much of virtual functions anyway? Last time I checked, it avoided any kind of polymorphism at all, for speed reasons. (and it doesn't really need to use much; C++ templates are nice tools that can make a pointer to function and a function object work in the same place just because you can stick "()" to the right of the passed parameter and it will compile, no run-time work needed).

c) (it seems to be implied, though not explicitly stated). Going faster than STL... in Python?

Re:Why we didn't use a bloom filter by zvrba on Saturday March 17, 2012 @05:11AM (#3716698)
Right. When I read that paragraph, my thought was that this guy has no clue what he's talking about.

STL is anything but object-oriented; Stepanov is one of the greatest critics of OO. Also, STL goes to great lengths to resolve everything at compile-time through, e.g., tag dispatch. No indirect calls are involved unless you introduce them yourself. Bounds-checking may be enabled in debug-mode in some implementations, but it can always be disabled, and ways of doing so are well-documented.

Re:Why we didn't use a bloom filter by gorset on Saturday March 17, 2012 @08:42AM (#3716940)
> a) How can you make standard-OOP-like method dispatch faster than vtables?

The JVM optimizes this by using (P)ICs, which are faster than regular vtables.

http://en.wikipedia.org/wiki/Inline_caching

Re:Why we didn't use a bloom filter by wisty on Saturday March 17, 2012 @10:00AM (#3717074)
> This fragment made me WTF

Well, he said he's used the STL for professionally 6 months, so he's a raw beginner by his own admission.

Re:Why we didn't use a bloom filter by viraptor on Saturday March 17, 2012 @10:31AM (#3717151)
I disagree with the "raw beginner" description. If you use something professionally, as in a day to day job, for 6 months, you're not going to be a beginner. It's a standard template library, not some crazy theory requiring a phd to apply. Unless you're trying to say that STL is so messed up you can't learn the basics of it in half a year?
Re:Why we didn't use a bloom filter by conroy on Saturday March 17, 2012 @03:50AM (#3716609)
In response to c, pypy has been getting ridiculously fast as of late. In some very specific (ie pointless) benchmarks, it can outperform C [1]. And it's only getting faster [2].

[1] http://morepypy.blogspot.com/2011/08/pypy-is-faster-than-c-a...

[2] http://speed.pypy.org/

Re:Why we didn't use a bloom filter by shin_lao on Saturday March 17, 2012 @12:09PM (#3717372)
Every language has got at least one benchmark saying "We're faster than C".
Re:Why we didn't use a bloom filter by ajays on Saturday March 17, 2012 @12:40PM (#3717442)
I was about to post that. Someone once joked, "a language isn't mature until it has a benchmark showing that it is faster than C".
Re:Why we didn't use a bloom filter by TeMPOraL on Saturday March 17, 2012 @12:12PM (#3717379)
It's good to know that, thanks :). I'll look into PyPy if I ever start doing some serious work in Python.
Re:Why we didn't use a bloom filter by DrJosiah on Saturday March 17, 2012 @04:01PM (#3718028)
I've updated the article to reflect the reasons why I pointed at vtables, which, as you say, are very likely incorrect.

And no, the article does not say that Python was performing faster than the STL. In the first sentence in the "What I Built" section, "Using C, I wrote a handful of lines of C code that took a sorted sequence of 4-byte integers that represented a Twitter user's followers, and I intersected that sequence against thousands of other similar sequences for other Twitter users." I mention C twice, despite it being awful grammar. I wanted to make it clear up front that this wasn't a "Python vs. X" post.

Re:Why we didn't use a bloom filter by Confusion on Saturday March 17, 2012 @04:15AM (#3716637)

  a) How can you make standard-OOP-like method dispatch 
  faster than vtables?
He doesn't claim you can: he just points out that it still adds overhead.
Re:Why we didn't use a bloom filter by vidarh on Saturday March 17, 2012 @05:02AM (#3716685)
It only adds overhead when using virtual member functions, in which case the equivalent in C is to "roll your own" vtables. You don't get away from that overhead.

If you don't use polymorphism, you don't need virtual member functions, in which case you don't pay the cost of a vtable.

This is one of the key tenets of C++: You pay for what you use, and only what you use.

Re:Why we didn't use a bloom filter by zeugma on Saturday March 17, 2012 @06:06AM (#3716759)
Actually you can do it using template but it is quite convoluted. (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.130....)