Skip to content

Evaluate circular_buffer_space_optimized for the console scrollback and other circular buffers #19738

Description

@kevinushey

boost::circular_buffer allocates its whole capacity up front. #19691 moved the console history (ConsoleHistory) to boost::circular_buffer_space_optimized, which treats the capacity as a maximum and allocates as elements are added, after R_HISTSIZE=999999999 tried to allocate gigabytes at startup. This issue is to evaluate whether the backend's other circular_buffers could or should switch too.

Buffer Elements Capacity Notes
ConsoleActions::actions_ (src/cpp/r/include/r/session/RConsoleActions.hpp) ConsoleAction (an int and a std::string) the console_max_lines pref: default 10,000, minimum 10, no maximum The likeliest candidate. The capacity is user-set, and all of it is allocated when the pref is applied: 32-40 bytes per slot, so 10 million lines would take 320-400 MB up front. Resized with rset_capacity() under a mutex.
PlotManager::plots_ (src/cpp/r/session/graphics/RGraphicsPlotManager.hpp) boost::shared_ptr<Plot> fixed at 100 About 1.6 KB; little to gain.
ViewerHistory::entries_ (src/cpp/session/modules/viewer/ViewerHistory.hpp) ViewerHistoryEntry fixed at 20 Little to gain.
ConsoleProcessInfo::outputBuffer_ (src/cpp/session/include/session/SessionConsoleProcessInfo.hpp) char fixed at 8,192 per terminal Usually full in an active terminal, so there's little to save, and growing it would add reallocations.

Things to weigh for ConsoleActions:

  • Whether a very large console_max_lines happens in practice, or whether a maximum on the pref would be the simpler fix.
  • The space-optimized buffer moves its elements each time it grows (doubling), and shrinks once its size drops to a third of what's allocated.

Separately, src/cpp/session/modules/SessionLists.cpp and src/cpp/session/include/session/SessionConsoleProcess.hpp include <boost/circular_buffer.hpp> without using it; those includes can go.

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions