Skip to content

Optimize stacktrace by avoid large allocation #3859

Description

achabense observed that pre-initializing internal vector in stacktrace to the maximum possible depth has noticeable performance impact:

basic_stacktrace _Result{_Internal_t{}, _Max_frames, _Al};

static constexpr size_t _Max_frames = 0xFFFF;

The CaptureStackBackTrace API does not have a way for determining the needed amount in advance.

Currently we don't maintain own array management in stacktrace and using vector to avoid dealing in one more place with:

  • copying/moving/assignments
  • allocators
  • ASan

What could we do:

  • Alex Guteniev (@AlexGuteniev) suggested that we can create a secret constructor for vector without initialization.
  • Stephan T. Lavavej (@StephanTLavavej) suggested we can use smaller allocation on stack, and then try maximum if smaller overflow, otherwise copy data from the stack and not allocate large amount. Smaller could be 32 entries, which is 32*sizeof(void*) bytes,
  • nicole mazzuca (@strega-nil-ms) suggested we could start with smaller allocations and grow in a geometric progression

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions