Issue 24333 - Inline ClassInfo with the vtbl
Summary: Inline ClassInfo with the vtbl
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: industry, performance
Depends on:
Blocks:
 
Reported: 2024-01-11 22:59 UTC by Walter Bright
Modified: 2024-01-16 08:57 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2024-01-11 22:59:39 UTC
deadalnix writes:

The current layout of objects is as follow:

+-----------+    +-----------+    +-----------+
|  __vtbl   +--->|  typeid   +--->| ClassInfo |
+-----------+    +-----------+    |           |
| __monitor |    |  method0  |    |    ...    |
+-----------+    +-----------+    |           |
|  field0   |    |  method1  |    +-----------+
+-----------+    +-----------+
|  field1   |    |    ...    |
+-----------+    +-----------+
|    ...    |
+-----------+
This causes a ton of extra indirections that are not necessary. instead the following layout ought to be used:

+-----------+    +-----------+
|  __vtbl   +--->| ClassInfo |
+-----------+    |           |
| __monitor |    |    ...    |
+-----------+    |           |
|  field0   |    +-----------+
+-----------+    |  method0  |
|  field1   |    +-----------+
+-----------+    |  method1  |
|    ...    |    +-----------+
+-----------+    |    ...    |
                 +-----------+
Alternatively, it is possible to have the pointer point at the first method and subtract to get the typeid. The important part is that there is only one indirection now.

https://forum.dlang.org/post/hteuczyclxajakrisxjd@forum.dlang.org
Comment 1 Walter Bright 2024-01-16 08:14:31 UTC
This is a challenging problem because the ClassInfo is of variable size. Embedding it with the vtbl[] would mean the variable parts would then have to be indirect.
Comment 2 Richard (Rikki) Andrew Cattermole 2024-01-16 08:57:37 UTC
Not necessarily.

You could reverse ClassInfo members, so that the fixed header goes after the variable length members.

It is the reverse of how you would normally want to work, where you increment the pointer, whereas this would decrement instead.