News for hackers. Stuff that matters.
Re:Std::string half of all allocations in the Chrome browser... by rwmj on Friday December 05, 2014 @12:44PM (#8705711)
I have in the past written many large C++ projects. I now try to avoid it as much as possible, but the last time I programmed in C++ was just two weeks ago[1], and it reminded me how bad it was -- terrible error messages, and abysmal performance of the final program. At some point I will have to replace it because the program doesn't meet our performance requirements, and no one can tell me why[2]. (Edit: Apparently [2] has been answered now)

[1] http://git.annexia.org/?p=virt-bmap.git;a=tree

[2] https://stackoverflow.com/questions/27152834/how-to-improve-...

Re:Std::string half of all allocations in the Chrome browser... by DannyBee on Friday December 05, 2014 @05:04PM (#8707182)
Of all the things you shudl expect from a non-C++ language, performance is highly unlikely to be on that list.

If you can't get something to be performant with C++, it's pretty unlikely you'll get it to be performant with most other languages.

(Unless you want to try it in fortran)

Re:Std::string half of all allocations in the Chrome browser... by tptacek on Friday December 05, 2014 @05:57PM (#8707425)
I expect C programs to outperform C++ programs, simply by virtue of being more explicit (about everything, from allocation to levels of indirection).
Re:Std::string half of all allocations in the Chrome browser... by vardump on Friday December 05, 2014 @06:45PM (#8707628)
Not always faster.

Try comparing qsort to stl::sort...

Hint: stl::sort is a lot faster. It can inline the comparison function. Ok, it just shows how slow function pointers are. I'm assuming compilers still can't optimize the function pointer away in qsort.

Of course a specialized sorter in C would be faster, one that can inline comparison function. C++ copy pasting automation... err, I mean templates are useful, because it can often inline your function and data type in the algorithm without using function pointers. At cost of generating same or similar algorithm code multiple times bloating the binary.

Re:Std::string half of all allocations in the Chrome browser... by nostrademons on Friday December 05, 2014 @01:53PM (#8706143)
Clang's error messages are much better than GCC - it will even spell-correct your typos and suggest which symbol you actually wanted to type. Around 2010 Google switched to a hybrid Clang + GCC environment (the same source code would be piped to both compilers, the error messages from Clang would be piped back to the user while the object files from GCC were linked to form the final binary), and C++ developer happiness skyrocketed.
Re:Std::string half of all allocations in the Chrome browser... by pja on Saturday December 06, 2014 @04:24AM (#8708789)
To be honest, I think gcc has pretty much caught up with clang with gcc-4.9 when it comes to error message quality.

I have a slight preference for the way clang chooses to highlight the entire AST parent node that it thinks is responsible for the error, but the approach g++ takes is perfectly clear.

Re:Std::string half of all allocations in the Chrome browser... by groby_b on Friday December 05, 2014 @08:39PM (#8708022)
It has been answered, and according to the answer, there's an easy 20x-30x speedup to be had. Maybe your problem is not C++ per se.

I wouldn't be surprised if std::unordered_set would yield further speedup. (It doesn't look like you need the order criterion). Other things worth trying are:

* Not using a set at all - it seems most sets only have 3-4 elements. You might as well use a vector. * It doesn't look like your intervals overlap, and it looks like they're already ordered. interval_map may be unnecessary, and it might be worth keeping the data in a simple vector. * You don't want to copy object_set, either. A const-ref is more than enough * And finally, if you want to veer into nit-pick territory, you want to use range-based loops. It might or might not yield better compiled code. It's definitely much more readable.

  for (const auto& iter : map->equal_range(window))
    for (const auto& obj: iter->second)
      f(iter->first->start, iter->first->end, obj.c_str(), opaque);
I don't disagree with the abysmal error messages, or the thought that C++ is a beast to learn and control. But if there's one thing it does give you, it's decent performance, if used properly.

Let's put it that way: The browser people don't write C++ because they think it's such an awesome language :)

Re:Std::string half of all allocations in the Chrome browser... by IvyMike on Friday December 05, 2014 @01:29PM (#8705980)
In #2, I'm curious why you didn't like sehe's answer?