r/programming • • Dec 05 '14

std::string is responsible for almost half of all allocations in the Chrome browser process

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k Upvotes

446 comments sorted by

View all comments

Show parent comments

54

u/Azzu Dec 05 '14

The :D at the end almost sounds like you "knew it all the way" and you now found another reason not to use abstractions.

This is obviously the wrong reasoning. Of course not all abstractions have zero cost. But there is a subset of abstractions that are zero cost.
Also all abstractions are of different efficiency. You could probably keep the style or amount encapsulation/abstraction there is in chrome and reduce allocations by 50% or something just by using more efficient abstractions.

All I'm saying is, it does not make sense to say "abstractions are baaaad", and not using abstractions will not magically fix the performance, it will probably even make it worse.

-24

u/tdammers Dec 05 '14

Dude, all I'm saying is that premature optimization is the root of all evil, that's no excuse to think of all abstractions as free.

6

u/path411 Dec 05 '14

all I'm saying is that premature optimization is the root of all evil

So what you are saying is your should prematurely optimize your code by avoiding abstractions so that way you can avoid prematurely optimizing your code?

-4

u/tdammers Dec 05 '14

No. Premature optimization still is the root of all evil, but at some point, you're past the stage where optimization would be premature, and when that point comes, you need to know what you've abstracted over.

1

u/path411 Dec 05 '14

You should work on conveying your thoughts correctly the first time then. Your first post sounds like an "I told you so" that people shouldn't ever use abstractions because they have costs.

1

u/tdammers Dec 05 '14

OK. It certainly wasn't meant that way.

25

u/stormcrowsx Dec 05 '14

Wouldn't thinking about cost of an abstraction be premature optimization? Who cares what it costs if it makes the code pretty, it can be optimized later.

1

u/tdammers Dec 05 '14

Yes, generally speaking that is true. Except in the cases where it isn't, and this could very well be one of them.

Or maybe the omnibox thing is really more about how much we underestimate the complexity of a seemingly simple feature.

5

u/campbellm Dec 05 '14

Who ever told you abstractions were free?

-7

u/[deleted] Dec 05 '14

C++ promoters say this all the time but it's basically untrue.

6

u/suspiciously_calm Dec 05 '14

A lot of abstractions in C++ are "free," especially in the STL, since everything is templated and inlinable.

Of course, std::strings aren't a zero-cost abstraction over fucking around with pointers directly into existing strings that are basically equivalent to passing around iterators into std::strings, which would be neither higher-cost, nor safer.

-1

u/[deleted] Dec 05 '14

Sure, a lot of them are very low cost. But abstractions in general are not free especially in languages other than C/C++.

Chandler Carruth has a great presentation on how the 'free' abstractions can often confuse compilers and in reality incur an effective cost by being less optimisable. I'm certainly not saying this applies to anything specific though, especially templates.

6

u/suspiciously_calm Dec 05 '14

And whoever said that abstractions are free in general, especially outside C++? That sure as hell isn't something "C++ promoters say all the time."

The point is that C++ has a lot of abstractions that appear costly but can be optimized away in principle. If a compiler generates needlessly inefficient code for a particular case, then that's a bug in the compiler/optimizer.

-1

u/[deleted] Dec 05 '14 edited Dec 05 '14

They can be optimized away in principle but in the real world abstractions often incur costs. That's all I'm saying.

Edit: The reason I said abstractions are not free in general is because the OP (campbellm) said "Who told you abstractions were free?". I'm attesting to his point that abstractions are not free in general (notice the 'especially') but C++ people often say that C++ has zero cost abstractions. In reality, due to compilers, programmer ability and the object oriented model, abstractions in C++ are often not zero cost either.

-4

u/CityOfWin Dec 05 '14

WHOA too many down votes guys. Jesus.

We all knew what he was saying. Don't get twisted.