Facebook C++ Conference

I managed to snatch tickets for the Facebook C++ Conference. I will be live blogging the event all day. Hope you enjoy!

20.49

Summary

Mainstream hardware is becoming permanently parallel, heterogeneous and distributed.
– Moore’s Mine is ending, but we know the answer: Open a new mine.
– As usual, the end of one wave overlaps the beginning of the next.
The long-term free lunch app requires lots of juicy latent parallelism expressed in a form that can be spread across a machine with a variable number of cores of different kinds – big/small/specialized cores, and local and distributed cores.
– The filet mignon of throughput gains is still on the menu, but now it costs extra effort – development, complexity, and testing.

20.12

Hardware is in motion! This talk is tougher to describe, as the presentation relies on many graphics.

20.00

We are observing the end of Moore’s Law. We can no longer rely on single-threaded performance increases, we need to go beyond multi-core to cloud-core and heterogeneous cores.

People forget about CPU parallelism which could be taken advantage of. Each core in facebook server, nehalem cpu, has 3 ALUs which are forgotten. You can do three simultaneous arithmetic calculations in a single thread! (SandyBridge has more than 3 ALUs). How do we use them?

17.39

Some Benchmarks

push_back speedup vs std::string is huge compared to the standard implementation. 400% speedup for 1 push_back call, 500% for 2 push back calls, less than 200% for 256k push_back calls. Plateau is 1.4 times faster than standard implementation.

17.34

The French Connection: jemalloc

Jason Evans wrote a great allocator for FreeBSD and it’s used everywhere at facebook.

fbstring solves fragmentation by knowing what jemalloc wants, the string will use what jemallocs wants to allocate its internal representation.

jemalloc allows reallocation in place – e.g. a large string built in a loop will be improved and occasional quadratic algorithms become linear! woot!

17.27

23 >> 15 (23 is the max chars in a fbstring, 15 is what other libraries use for string)

23, 15 is not a big deal… actually it is because at facebook they have many protocols that store ints as strings, many ints are smalls but not all! User ids at facebook are randomly generated, 64 bits. Almost all these ids don’t fit in 15 chars… thus will spill into allocated memory but with fbstring none will spill and thus be highly optimized.

17.24

fbstring has control. fbstring lets them take full control over where data goes, optimizes memory allocation. The performance impact is huge.

Andrei is making fun of Python/Java programmers for not knowing what happens in memory.

17.22

fbstring data layout

Small
hello, world! slash0 | 9 (9 is the number of bytes unused, allows them to append quickly and the last byte is used as a null terminator when there are no more bytes unused)

Medium/Large
char* data | size_t length | size_t capacity | FF
(if FF is all ones then we will consider the string in this format otherwise in the small format.

We are live again! Andrei is speaking, the title of the talk is Sheer Folly.

C++, why do we care? Why do we still care about system languages.
1. Data Layout Control – How data sits in memory? C++ allows you to literally tell where ever byte goes. Example: fbstring. Hang on, let’s not invent the wheel here but we did… demotivation for std string : 1 – std::string as a container is fail – 2 – std::allocator is fail – 3 – std::char_traits is fail – 4 – algorithm integration is fail – 5 – copy-on-write became fail… motivation: 1 – because its there which lets us take existing pre and link against fbstring

2. Cooperation with the allocator

3. Copy on write optimization

16.06

Lunch Break! Following lunch, Andrei Alexandrescu will be making an announcement of interest to C++ programmers around the world. Stay tuned.

VC11 compiler rejects the explicit instantiation. MS has confirmed two compiler bugs but a workaround exists.

The specialization of the size of the const char, we can fix that but it is left as homework to the attendee.

15.56

All you need to do is take a look at the g++ error message, copy it into a source file and this will explicitly instantiate the template but you have to double check the type deduced by the compiler because it may not be the same as the type passed into the function. But g++ is so self aware that it will actually compile/link/run. 😀

!!!
Function templates can’t be specialized, only overloaded. But the form of forwarding templates is constrained, the only parameter type that works is T&&!. Works = handles all combos of const/non-consts expressions.

this will go through several layers, and thus perfect forwarding becomes extremely desirable.

15.17

Perfect forwarding is our main interest. Perfect forwarding allows you to pass params straight through templates, we have a common use case, when we build constructors in templated classes. This is when we have problems with the new move construct… perfect forwarding is difficult because we will have to be careful with rvalues and rvalue references.

15.13

In order to support moves in C++11, we have a new construct called rvalue references. New syntax type&& will give you rvalue references. Rvalue references identify candidates for moving versus copying.

Must be careful, in function templates type&& are not really rvalue references. They mean “bind to anything” -> universal references.

Scott will be speaking about C++11. Lvalues are generally expressions that take an address and they are important for taking copies, copy requests. In C++11, copy requests can often become move requests, the langauge is now taking more care into the difference between l and r values.

15.05

C++ is seeing a new growth because we can’t get faster processors very much anymore. Scott will now give his talk.

15.04

Opening remarks starting, Andrei Alexandrescu is our MC, hosting the first #fb #cpp #conf. There is a great demand and knowledge for C++ and facebook is very excited about this new growth in interest.

14.46

Slides are coming up: Adventures in Perfect Forwarding by Scott Meyers. Opening remarks are expected to be on time. #fb #cpp #conf

14.31

Blinds are going down here at the fb cpp conf. Stage is being prepared. 30 minutes to go before the opening remarks. Scott Meyer’s talk will follow.

Thanks vm for the live comments.
Someone did post it onto Y Hacker News, but, the hipsters there only seem to comment on Python, Lisp, and 1001 varieties of the same JS framework, and seem to ignore C++. Lest they try to understand it I suppose!