GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Optimize stream output for piecewise distributions.

The `operator<<` for piecewise distributions avoids creating a temporary vector, improving performance.

The operator<< for piecewise_constant_distribution and piecewise_linear_distribution now directly accesses the internal _M_int and _M_den members of the _M_param structure, avoiding the creation of a temporary vector. This improves the performance of streaming these distributions, particularly when they contain a large number of intervals.

In Details

This commit optimizes the stream output (operator<<) for piecewise_constant_distribution and piecewise_linear_distribution in libstdc++. By befriending operator<< for the param_type, the implementation can now directly access _M_int and _M_den members, avoiding a temporary vector allocation. This improves performance without impacting other subsystems.

For Context

In C++, you can output data to streams (like the console or a file) using the << operator. This commit optimizes how piecewise_constant_distribution and piecewise_linear_distribution objects (which represent probability distributions) are outputted to streams. Previously, the output process involved creating a temporary data structure, which could be slow. This commit optimizes the output process by directly accessing the internal data of the distribution objects, avoiding the need for the temporary data structure. This results in faster output and improved performance.

Filed Under: libstdc++randomoptimizationiostreams