[PATCH] D125403: [Serialization] Delta-encode consecutive SourceLocations in TypeLoc

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 10:34:21 PDT 2022


sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a subscriber: mgorny.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Much of the size of PCH/PCM files comes from stored SourceLocations.
These are encoded using (almost) their raw value, VBR-encoded. Absolute
SourceLocations can be relatively large numbers, so this commonly takes
20-30 bits per location.

We can reduce this by exploiting redundancy: many "nearby" SourceLocations are
stored differing only slightly and can be delta-encoded.
Randam-access loading of AST nodes constrains how long these sequences
can be, but we can do it at least within a node that always gets
deserialized as an atomic unit.

TypeLoc is implemented in this patch as it's a relatively small change
that shows most of the API.
This saves ~3.5% of PCH size, I have local changes applying this technique
further that save another 3%, I think it's possible to get to 10% total.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125403

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/SourceLocationEncoding.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/unittests/Serialization/CMakeLists.txt
  clang/unittests/Serialization/SourceLocationEncodingTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125403.428710.patch
Type: text/x-patch
Size: 38172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220511/fba8e5a9/attachment-0001.bin>


More information about the cfe-commits mailing list