Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache standard objects (Array, Object, etc) and there prototypes #613

Closed
HalidOdat opened this issue Aug 8, 2020 · 2 comments · Fixed by #722
Closed

Cache standard objects (Array, Object, etc) and there prototypes #613

HalidOdat opened this issue Aug 8, 2020 · 2 comments · Fixed by #722
Labels
discussion Issues needing more discussion execution Issues or PRs related to code execution help wanted Extra attention is needed performance Performance related changes and issues

Comments

@HalidOdat
Copy link
Member

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 HalidOdat added help wanted Extra attention is needed performance Performance related changes and issues discussion Issues needing more discussion execution Issues or PRs related to code execution labels Aug 8, 2020
@HalidOdat HalidOdat changed the title Cache chandard objects (Array, Object, etc) and there prototypes Cache standard objects (Array, Object, etc) and there prototypes Aug 8, 2020
@54k1
Copy link
Contributor

54k1 commented Aug 22, 2020

@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
Copy link
Member Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Issues needing more discussion execution Issues or PRs related to code execution help wanted Extra attention is needed performance Performance related changes and issues
Projects
None yet
2 participants