Static Shapes (Hidden Classes
)
#2813
Labels
E-Hard
Hard difficulty problem
execution
Issues or PRs related to code execution
performance
Performance related changes and issues
This is a possible optimization to improve
Context
construction, the biggest bottleneck is builtin initialization and as we add more builtins, the time needed to initialize them will increase, so I thought of the following optimization:When we initialize builtins we always construct them in the same way, with the same property names and slot index and attributes. In a way the builtin shapes are static, It only changes when the user wants to delete or extend the builtin
Object.someNonBuiltInFunction = ...
.Why not pre-initialize them at compile time, having a
static
phf
table that contains the shape (its property name and descriptor attributes), and in theory a perfect hash function should be faster, since there are no collisions and also take up less space. This also has the big advantages that it can be shared between builtins from different realms, since it'sstatic
it can also be shared across threads.The only thing that has to be constructed at runtime is the object storage (
Vec<JsValue>
) which contains the values of the property names. And In the future when we implement #1372 we will be able to eliminate this overhead too :)And if we want to extend or delete a property, we convert it into a unique shape (copy-on-write) with the changes (as we are already doing by default with all the builtins).
The text was updated successfully, but these errors were encountered: