TL;DR crash annotations can be recorded so that their value is read and
serialized only at crash-time, this means that even frequently updated
ones have no performance cost at runtime.
Longer version:
Crash annotations have been historically recorded in C++ using the
CrashReporter::AnnotateCrashReport() method. This would serialize the
annotation value into a string and then store it in a table that would
later be attached to a crash. A new way of recording crash annotations
is now available via CrashReporter::RegisterAnnotation<TypeName>(). This
method takes an address to the variable holding the annotation's value
(which can be a boolean, integer, string, etc...) and records it among
the annotations. At crash time we'll extract the values of the
annotations from these addresses and serialize them into the crash
report. This means that in the meantime you can update the value of the
annotation at will without having to re-record it every time. The last
value in memory will be picked up automatically if we crash.
One advantage of this system is that you can now pick a variable that is
updated very frequently, even thousands of times per second, and still
be able to record it in a crash with no performance impact. You only
have to ensure that the memory holding the value is alive when we crash,
even though if it isn't the annotation will just be ignored.
You can still record annotations the old way by using
CrashReporter::RecordAnnotation<TypeName>(). This will make a copy of
the value you passed in and keep it around with the other annotations.
You can find more details in bug 1831092 [1].
Gabriele
[1] Record all annotations using the new pull-based system and remove
the annotation table
https://bugzilla.mozilla.org/show_bug.cgi?id=1831092