Facade tuples

The compiler provides facade tuples to avoid serialization processing.

When tuples are transmitted between PEs, they go through the transport, which requires serialization to a binary format on the sending side and deserialization from the binary format on the receiving side.

In certain high-end and performance-sensitive applications, the need for avoiding binary serialization arises. When an operator manipulates only a select few attributes from a tuple, the serialization might constitute a non-negligible cost. Another relevant case is large attributes, such as a long list of bytes, which result in costly copies during binary serialization. The SPL compiler provides facade tuples for avoiding the serialization cost. Facade tuples provide the same API as the regular tuples, but avoid copying data between transport buffers and the tuple memory. By matching the tuple memory layout to the on-the-wire layout the cost is avoided. The -k, --prefer-facade-tuples option instructs the SPL compiler to generate facade tuple code when possible. Not all SPL tuple types can be handled by facade tuples. Facade tuple types consist of the following types:

  • Facade scalar types: Primitive types except blob, rstring, ustring, and xml.
  • Facade string types: Bounded rstring.
  • Facade collection types: Bounded lists and sets whose element types are facade scalar types and bounded maps whose key and value types are facade scalar types of the same size. For example, int64 and float64.

For non-facade tuple types, regular tuple code is generated irrespective of the compiler options.

Facade tuples, while more efficient from the perspective of serialization and deserialization, have a few downsides during tuple manipulation:

  • When default constructed, facade tuples are allocated on the heap, not on the stack.
  • Accessing facade tuple attributes might result in unaligned memory access. On operating systems where unaligned memory access is not allowed, facade tuple optimizations cannot be applied.

Developers that are interested in taking advantage of facade tuples are advised to evaluate the benefits with application-specific experimentation.