Minimal Overhead Messaging Support Using Runtime Agnostic Memory Layouts
Abstract
This REP proposes a re-design of the rosidl messaging system to broaden the scope of zero-copy data transport, including transports that deal with segregated memory models and processes implemented in different programming languages.
In particular, it specifies language-specific message views over runtime-agnostic memory representations, a way to constrain otherwise variable-size messages, and middleware extensions to construct and exchange those views using externally managed storage.
The design does not prescribe a programming language, middleware, memory allocator, shared-memory mechanism, or wire format. It does require language runtimes and type support implementations to agree on the structure and lifetime of the memory representation they exchange.
Motivation
rosidl is one of the oldest subsystems of ROS 2. Initial research dates back to 2013. C and C++ message generators were first released with Alpha 1, each with their own runtime representations. Language-specific, member-based interfaces were simple enough to implement and verifiably performant. The first DDS based middlewares had their own vendor-specific IDL to comply with, for interoperability and full feature support, and their own wire formats. Some data processing cost (ie. copy, conversion, serialization) had to be paid one way or another and it was deemed affordable.
rosidl design hasn’t changed substantially since then. Unfortunately, even if well suited for ROS systems distributed over many hosts in a network, its simplicity sacrifices performance for the fairly common single host topology.
Autonomous systems can produce vast amounts of data in a relatively short span of time and every non-functional data processing step slows down data transport, up to a complete halt if data paths are not carefully designed. Multiple features have been added to ROS over time to optimize these data paths: message loaning, shared-memory transports, intra-process communication, type adaptation, and type negotiation. Many of these features implement some often narrow form of so called zero-copy data transport: moving data from peer A to peer B with minimal overhead.
Yet the rosidl design precludes full application of more general forms of zero-copy data transport. As of early 2026, middleware zero-copy data paths cannot generally cross the language boundary because there is no common runtime representation. Moreover, variable-length members usually refer to separately allocated memory, so even within one language only a small subset of message types has a contiguous and transportable in-memory layout. The subset is so narrow that not even common message structures containing strings or sequences qualify.
rosidl design must change to properly accommodate zero-copy data transport.
Specification
The proposed re-design hinges on one central idea: rosidl messages become language-specific views over a language-agnostic memory representation.
For a publisher to request externally managed storage, the maximum storage requirement must be knowable when that storage is obtained. A publisher therefore constrains every variable-size part of the message, either when the endpoint is created or when an individual message is borrowed.
A subscriber does not need to know the publisher’s constraints. The received representation must describe the actual extent of its variable-size members, allowing a subscriber to construct a view bounded by the received storage rather than by the publisher’s allocation policy.
The following abstractions apply to messages as well as request-response message pairs for services.
Views
Generated messages are language-specific data interfaces or views, rather than necessarily self-contained data structures. Instead of imposing a language-specific memory layout, these views provide semantically meaningful and idiomatic access to a memory representation.
A view may own its storage, as it typically does when default constructed, or borrow storage managed by another component, as it does when constructed over a middleware loan. Both forms must expose substantially the same message interface so that application logic does not depend on the storage owner.
An implementation may use descriptors, proxy objects, language properties, buffer protocols, or other suitable constructs to implement a view. These are language implementation details and are not part of the portable message model.
Storage
Storage exchanged across the generic type support and middleware boundaries is described as one or more memory regions. A memory region comprises an address, a byte extent, and implementation-defined attributes:
1
2
3
4
5
6
7
8
9
typedef struct rosidl_memory_s {
void * address;
int attributes;
} rosidl_memory_t;
typedef struct rosidl_memory_region_s {
rosidl_memory_t location;
size_t size;
} rosidl_memory_region_t;
The address assumes a flat memory space local to the process using the view. It need not be meaningful in another process: transports remain responsible for mapping, translating, or otherwise making their storage accessible there.
Attributes qualify a region, e.g. which device it has been allocated to, which memory section it was allocated from, what operations are permitted on it, or whether explicit synchronization is necessary. The meaning of attributes and any operation such as to_cpu() is deliberately left for future specification.
Language runtimes must be able to construct view members over these regions while preserving normal message semantics. An implementation may also use ordinary dynamic allocation for owning messages. This permits fixed external storage, memory pools, shared-memory mappings, device memory, and conventional heap storage to coexist behind the same view interface.
Zero-copy transport does not require every possible representation to be one contiguous allocation. It requires the sender, receiver, type support, and transport to agree on a representation that can be transferred or mapped without copying. A contiguous representation is particularly useful for shared memory and for direct network transmission.
Constraints
Constraints characterize the maximum storage requirement of otherwise variable-size messages. Generated message code provides a language-specific constraint structure matching the message structure. It contains bounds for variable-length strings and sequences and recursively contains constraints for nested messages and their elements.
For example, constraints for an image message may contain a maximum encoding length and a maximum data sequence length. The exact generated syntax is language-specific; the constraint semantics are not.
Constraints are carried across language and middleware boundaries in a language-neutral envelope:
1
2
3
4
5
6
typedef struct rosidl_message_type_constraints_s {
void * type_specific;
size_t max_string_length;
size_t max_total_size;
bool strict;
} rosidl_message_type_constraints_t;
type_specific refers to generated per-message constraints. max_string_length and max_total_size provide blanket limits, where zero means no additional limit. strict requests full per-field validation instead of permitting a cheaper aggregate check when one is sufficient.
Constraints establish upper bounds, not the actual size of a message. Actual string and sequence lengths remain part of the memory representation. Constraints therefore need not be communicated with each sample, nor agreed upon by every subscriber.
Constraints associated with an endpoint form its baseline. Constraints supplied for an individual loan may tighten that baseline but may not loosen it. A request for a looser per-loan constraint must be rejected rather than silently exceeding the resources provisioned for the endpoint.
Publisher and subscription baselines are independent. A subscription constraint describes the resources and validation policy of that subscription; it is not required to reproduce the publisher’s allocation constraint. Likewise, omitting constraints from an individual take does not discard the subscription baseline. It only means that the take adds no tighter, sample-specific restriction.
Runtime representation
This REP does not mandate a particular in-memory or wire representation.
To support a zero-copy data path, a representation must:
- have a layout that can be interpreted independently of the programming language used to access it;
- encode the actual extent of variable-size members;
- define alignment, padding, byte order, and scalar representation;
- be bounded by the storage region supplied to the type support; and
- permit construction of safe language-specific views whose lifetime does not exceed that of the storage.
Using the wire representation as the in-memory representation is one valid strategy. It can eliminate conversion between memory and wire forms when the transport and host agree on the relevant representation details. It is not the only strategy: a middleware may use another shared-memory layout and serialize only when communication leaves the host or encounters an incompatible peer.
Type support requirements
Language-specific type support bridges generated message views and the common memory representation. Despite being language-specific internally, it exposes a language-neutral operation table so middleware implementations need not know which runtime owns the view.
A language binding may implement that table directly or bridge to another language implementation. In either case it must preserve the representation, ownership, and lifetime contracts specified here.
The operation table must support:
- computing the expected storage requirement for a type and its constraints;
- computing the actual representation size of a message;
- constructing a writable message view over supplied storage;
- casting a received representation into a read or read-write message view;
- serializing into and deserializing from supplied storage when a copy path is required;
- validating a message against constraints;
- querying and releasing the storage backing a view; and
- destroying a view without assuming ownership of externally managed storage.
An implementation may additionally support in-place finalization of a writable view. This permits a publisher to reserve storage for the constrained maximum, let application code populate the view, and then convert that view into the representation carrying only the actual message content without allocating another buffer.
Constrained type support handles may cache layouts or other derived metadata. Such handles must own or otherwise preserve the constraints from which they were derived.
Ownership and lifetime
A view constructed over external storage borrows that storage. It must not outlive the storage region and must not retain member references after the loan is returned.
Exactly one terminal operation consumes each constructed or cast view:
- destroy tears down the language view while leaving storage ownership with its current owner; or
- release tears down the view and returns its backing region to the caller as one operation.
A non-consuming query may expose the backing region while the view remains valid. This is useful when a middleware must correlate a language-level view with an outstanding transport loan.
Language bindings may wrap this contract in RAII objects, context managers, reference-counted objects, or equivalent constructs, but must preserve the same single-owner lifetime semantics.
Middleware changes
Message constraints may be supplied when publishers and subscriptions are created:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
rmw_publisher_t *
rmw_create_publisher_with_constraints(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_support,
const rosidl_message_type_constraints_t * type_constraints,
const char * topic_name,
const rmw_qos_profile_t * qos_profile,
const rmw_publisher_options_t * publisher_options);
rmw_subscription_t *
rmw_create_subscription_with_constraints(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_support,
const rosidl_message_type_constraints_t * type_constraints,
const char * topic_name,
const rmw_qos_profile_t * qos_profile,
const rmw_subscription_options_t * subscription_options);
These calls complement the unconstrained endpoint creation APIs. Constraints apply to every message affected by the endpoint. Middleware implementations may use them to select a transport, precompute layouts, size pools, preallocate resources, and validate samples.
Constraints may also be supplied for individual loans:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
rmw_ret_t
rmw_borrow_loaned_message_with_constraints(
const rmw_publisher_t * publisher,
const rosidl_message_type_support_t * type_support,
const rosidl_message_type_constraints_t * type_constraints,
void ** ros_message);
rmw_ret_t
rmw_take_loaned_message_with_constraints(
const rmw_subscription_t * subscription,
const rosidl_message_type_constraints_t * type_constraints,
void ** loaned_message,
bool * taken,
rmw_subscription_allocation_t * allocation);
Per-loan constraints refine endpoint-wide constraints. Middleware implementations may reject unsupported constraints or loan requests. Existing unconstrained APIs remain valid and behave as if no additional constraints were supplied.
This REP does not require every middleware to provide zero-copy transport. A compliant implementation may return RMW_RET_UNSUPPORTED and continue to support ordinary publish and take operations.
Rationale
Middlewares that feature zero-copy data transport often implement message loaning APIs and rely on type support to determine the size of an allocation and delegate message construction. This design allows ROS nodes that publish data to use these APIs for messages that are variable-size in their IDL definition but bounded in a particular deployment.
This is reasonable in many cases, e.g. sensor drivers with a finite set of resolution settings, often preconfigured to a single setting on bring up. By constraining the size of variable-length members, storage requirements become knowable before a loan is granted and memory locality can be achieved.
Subscribers need not share those deployment constraints. The actual received representation remains structurally consistent with the message type and carries its own variable-member extents. A subscriber can therefore view a sample from any compatible publisher without reproducing that publisher’s allocation policy.
Since the representation is independent of the language view, the same storage can be exposed to applications written in different languages. The language boundary becomes a view-construction concern rather than a mandatory conversion boundary.
As a second order effect, constraints communicate resource needs and enable preallocation. Given message types, constraints, and QoS profiles, a middleware can reason about endpoint resources early and spare non-deterministic calls during steady state operation. This is a staple of real-time systems.
Backwards Compatibility
In order to ensure owning and non-owning views offer a consistent interface, language implementations may need alternatives to standard library containers. These alternatives should be functionally equivalent wherever practical, but may not be type equivalent and therefore may introduce source or ABI incompatibilities.
High-level languages such as C++ and Python can provide a softer transition through namespaces, import aliases, compatible container protocols, and conversion helpers. C has fewer such mechanisms and may require a more explicit API transition.
Wire compatibility is independent of source compatibility. Implementations should retain the established ROS wire representation whenever practical or provide ordinary serialization fallbacks so new and existing endpoints can coexist. A zero-copy optimization must not silently change topic type semantics.
Existing unconstrained endpoint creation, publish, take, and loan APIs remain available. Applications not opting into constrained messages keep their existing behavior.
How to Teach This
A primary goal of this re-design is to remain compatible with standard ROS programming patterns. Application developers should mainly learn one additional concept: a loan for a variable-size message needs bounds.
In a statically typed language, those bounds may be provided when a publisher is created:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sensor_msgs::msg::experimental::Image::Constraints image_bounds;
image_bounds.encoding.size = 4;
image_bounds.data.size = 640 * 480 * 3;
auto publisher = node->create_publisher<sensor_msgs::msg::experimental::Image>(
"image", 10,
rosidl_runtime_cpp::MessageConstraints<
sensor_msgs::msg::experimental::Image>(image_bounds));
auto loan = publisher->borrow_loaned_message();
auto & image = loan.get();
image.width = 640;
image.height = 480;
image.encoding = "rgb8";
image.data.resize(640 * 480 * 3);
publisher->publish(std::move(loan));
A subscriber continues to consume a normal message interface. Its language binding may expose the loan through a scoped callback, context manager, or ordinary callback whose execution owns the loan for its duration:
1
2
3
4
def on_image(image):
print(image.width, image.height, image.encoding)
subscription = node.create_subscription(Image, 'image', on_image, 10)
Developer guides will be necessary to maintain and evolve the implementation. Complete guides for language runtimes, generators, type supports, and middleware integrations are a must, and the reference implementation should bring its own.
Reference Implementation
The reference implementation exercises the design using experimental C++, CPython, XCDRv1, and Fast DDS support. These choices validate the proposal but are not normative requirements of the REP. It can be found at Ekumen-OS/zero_copy_rosidl.
XCDRv1 representation
XCDRv1 is used as both the transferable representation and the external storage layout viewed by generated messages.
It was chosen because it is already common in ROS 2 DDS communication, sequentially represents the data needed by rosidl messages, and describes variable-member extents well enough to reconstruct a view when the type is known. Using the established representation also lets ordinary serialization and zero-copy paths remain mutually intelligible when they use compatible encapsulation and data representation settings.
The prototype deliberately targets XCDRv1 plain CDR. Other encodings, endianness combinations, and evolvable XTypes encodings require equivalent layout parsing and compatibility work before they can be viewed directly.
Experimental message runtimes
The experimental C++ runtime provides scalar, string, sequence, and array views that can either own memory or use fixed external regions. Generated messages compose these containers and expose generated Constraints and ExternalStorage structures.
The CPython runtime exposes generated Python-facing message handles and constraint objects through pybind11. Each experimental message class carries a MessageTypeBridge that lets rclpy retrieve the corresponding C++ type support, wrap a C++ message pointer in a non-owning Python object, and translate generated constraint objects without transferring ownership. The reference implementation therefore reuses the C++ XCDR type support for Python messages rather than providing a separate CPython XCDR type support package.
XCDR type support family
The reference implementation uses a language-neutral outer XCDR operation table and language-specific inner state. The outer table defines the operations required by this REP. Generated C++ implementations provide field traversal, layout construction and parsing, serialization, casting, validation, compaction, and view lifetime handling. Generated CPython message classes reach those operations through rosidl_runtime_cpython::MessageTypeBridge.
The generated CPython bridge implementation is emitted by core/ros2/rosidl_python/rosidl_generator_py/resource/msg__experimental_impl.cpp.em:160-202. Python constraint objects are provided by rosidl_runtime_cpython.constraints; there is no separate rosidl_typesupport_xcdr_cpython package in the reference implementation.
Constrained type support handles own cloned constraints and cache a layout derived from them. On publish, a writable view may be compacted in place so the same middleware-owned block becomes its XCDR representation without allocating an intermediate serialization buffer.
ROS client and middleware plumbing
Dedicated constrained endpoint creation and loan APIs carry constraints through rclcpp and rclpy, then through rcl, into rmw. Existing APIs delegate to these paths with no additional constraints where practical.
rclcpp exposes typed MessageConstraints<T> and constrained overloads for endpoint creation and publisher borrowing. rclpy accepts rosidl_runtime_cpython.constraints.MessageConstraints objects and wraps loaned Python messages in an object whose lifetime returns the middleware loan.
The reference rclcpp and rclpy executors perform subscriber loans through rcl_take_loaned_message(). That function delegates to rcl_take_loaned_message_with_constraints() with a null per-take constraint, so the subscription-wide baseline remains in force and the take adds no tighter restriction. Applications using the lower-level rcl or rmw APIs may supply a tighter per-take constraint explicitly. This distinction is intentional: endpoint constraints provision and bound the subscription, while per-take constraints optionally narrow one loan.
Fast DDS integration
Fast DDS is the target middleware because it provides writer and reader loans, shared-memory transport, and data sharing within the same implementation.
A dedicated XcdrTypeSupport adapts the language-neutral XCDR operations to Fast DDS TopicDataType. It resolves the applicable language type support, derives boundedness and allocation size from constraints, and implements ordinary serialization as well as typed-view loans.
On borrow, the integration obtains middleware storage and constructs a writable language view directly over it. On loaned publish, it recovers the outstanding transport loan from the view’s backing region, compacts the view into XCDR in place, and writes that same block.
On take, a compatible loaned payload is cast into a language-specific view. Returning the view destroys its language-level state and returns the underlying sample to Fast DDS.
Fast DDS distinguishes plain and non-plain topic types internally. The prototype handles both forms: a plain sample can directly expose its payload, while a non-plain reader loan uses a holder whose type support casts the received payload into a view. This distinction is an implementation constraint of Fast DDS, not a distinction in the portable design.
Rejected Ideas
Replace
rosidlwith a different data interchange technology, featuring the missing bits for cross-language zero-copy transport (e.g. FlatBuffers). While tempting, such a change would completely break compatibility. Breaking API, ABI, and over-the-wire compatibility across the board for an ecosystem as vast as ROS would result in either limited community adoption or fragmentation.Mandate one shared-memory or wire representation. This would make the proposal unnecessarily dependent on one middleware or transport. The design instead specifies the operations and lifetime contract needed to expose a compatible representation through language-specific views.
Communicate publisher constraints with every sample. Constraints describe allocation maxima, not actual message contents. A self-describing representation already carries actual variable-member extents, so transmitting constraints would couple subscribers to a publisher’s resource policy without helping them interpret the sample.
Known Issues
Direct viewing depends on representation compatibility. A received payload can only be cast when its encoding, byte order, alignment rules, and type layout are supported. Incompatible representations require an ordinary deserialization or conversion path.
Middleware zero-copy capabilities differ. Fast DDS imposes boundedness, plainness, memory-policy, pool-size, and data-sharing compatibility rules of its own. Other middlewares will impose different conditions. The common APIs therefore permit an implementation to reject a loan while retaining copy-based communication.
Memory attributes are not yet meaningfully specified. The
attributesfield is propagated through the APIs but is not yet assigned portable device, memory-section, permission, or synchronization semantics.
Copyright/License
This document is marked CC0 1.0 Universal. To view a copy of this mark, visit https://creativecommons.org/publicdomain/zero/1.0/.

