protozero: Pack length fields for short nested messages

Previously protozero uses 4 bytes for all nested message length fields
despite the actual length of the message. This can be wasteful,
especially for small nested messages.

This patch adds logic to pack the length field for short messages
(<= 127 bytes) into a single byte. This is done by shifting back the
already-written message data into the preceeding length field. The
assumption is that this data will still be in the L1 cache, so the
cost of shifting it will be negligible.

Latency benchmarking results (cloudtop):

Before: go/paste/5009322705682432
After: go/paste/5758827482841088

(tl;dr: any changes seem to be within noise)

For a size benchmark, I loaded https://theverge.com on a fresh
Chrome profile while tracing all categories (just Chrome, no traced)
for 10 seconds. The uncompressed trace sizes were:

Before: 64302974 bytes
After: 56297094 bytes (-12.5%)

Bug: b/135511481
Change-Id: Ia2d4c81160af2bcdf7d2df342124408719d8f9fe
10 files changed
tree: b9f9f01c4633822d26aa6fb92c41d7e8188edcca
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. python/
  13. src/
  14. test/
  15. third_party/
  16. tools/
  17. ui/
  18. .clang-format
  19. .clang-tidy
  20. .git-blame-ignore-revs
  21. .gitattributes
  22. .gitignore
  23. .gn
  24. .style.yapf
  25. Android.bp
  26. Android.bp.extras
  27. BUILD
  28. BUILD.extras
  29. BUILD.gn
  30. CHANGELOG
  31. codereview.settings
  32. DIR_METADATA
  33. heapprofd.rc
  34. LICENSE
  35. meson.build
  36. METADATA
  37. MODULE_LICENSE_APACHE2
  38. OWNERS
  39. perfetto.rc
  40. PerfettoIntegrationTests.xml
  41. PRESUBMIT.py
  42. README.chromium
  43. README.md
  44. TEST_MAPPING
  45. traced_perf.rc
  46. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.