Nontrivial pointer type walls and AST memory usage

Hello,

I’ve committed some fixed recently that enable one to experiment with nontrivial Type implementations. I’m not proposing or suggesting any changes in this email, but I do have a few questions at the end.

As a starter experiment that was easy (and non-serious), I shrank sizeof(Type) to 32 bits to see if the memory savings yielded any quick performance gains when building Swift.swiftmodule. I did not change the alignment of TypeBase from 8 to 4 bytes due to some PointerIntPair code that uses all 3 bits, but this would have yielded some additional memory savings due to padding minimization.

Somewhat surprisingly, the performance didn’t improve. I suspect that without careful data structure layout, accidental padding is too easy to trip over under in LP64 environments.

To repeat myself, this experiment was done because it was easy, not because it was serious. (Well, that and I remember how much @Chris_Lattner3 is annoyed by the “wasted” bits in pointers. Hi Chris!)

I do have a few questions though for the experienced developers on the list:

  1. To what extent to people think that nontrivial pointer type walls are worth pursuing?
  2. Do people expect that storing the AST node kind in a given type wall to be worth it? Doing so would help us avoid memory loads when using isa or dyn_cast; and extracting the pointer from the type wall would simply require either a logical-and or logical-shift-right instruction.
  3. Similarly, do people expect that storing critical RecursiveTypeProperties in the Type type wall would be advantageous?
  4. What is the reasonable upper limit for amount of memory used by the AST? I ask because on 64-bit platforms, having a contiguous AST can save additional memory, make the allocators faster, and as a bonus make more pointer bits predictable so that type walls can use them if they desire.

Dave Z.

I 💖 memory efficiency!

Can you explain more about what you mean by a ‘type wall’? Is there a before/after example of what you’re experimenting with?

Hi @Chris_Lattner3 — By “type wall”, I mean explicit C++ type “wall” around around another (often implicit) C++ type. For example, "struct CharWall { char *bytes; };" would be an explicit type “wall” around an implicit C++ type: “char *”.