What is the problem with the current implementation?
The problem is that when we access a standard object we use .get_field() to get it from the global object, the problem is that we have to do a hashmap lookup and .get_field() does other checks that are not necessary.
we have to do:
interpreter.global().get_field("Object")
or to get the prototype we have to do two HashMap lookups
interpreter.global().get_field("Object").get_field("prototype")
Proposed changes
Store the common standard objects in the realm/interpreter as struct fields maybe:
struct StandardObject {
object: GcObject,
prototype: GcObject,
}
struct StandardObjects {
object_object: StandardObject,
array_object: StandardObject,
function_object: StandardObject,
error_object: StandardObject,
// ... other standard objects ...
}
This way if we need to access the prototype of for example Function object we do something like:
interpreter.standard_objects.function_object.prototype
This way we avoid all the unnecessary HashMap lookups and the checks from .get_field()
@HalidOdat, I have made some preliminary changes here based on what you have suggested.
Could you have a look? We can extend this so that the entire codebase uses standard_objects wherever possible.
@HalidOdat, I have made some preliminary changes here based on what you have suggested.
Could you have a look? We can extend this so that the entire codebase uses standard_objects wherever possible.
This looks good! There are still something that we can improve in this initial implementation, we should create a draft PR so we can better comment on it and see what the benchmark speed gains there are.