-
Notifications
You must be signed in to change notification settings - Fork 683
Optimize LCache operation. #1116
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
Conversation
Binary sizes (bytes) |
Impressive results :) |
if (!is_cached) | ||
for (uint32_t entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++) | ||
{ | ||
if (entry_p->object_cp == object_cp && entry_p->prop_p == prop_p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to attach the same property to different objects? What I'm trying to say here is can the following code work here?
if (entry_p->prop_p == prop_p)
{
JERRY_ASSERT (entry_p->object_cp == object_cp);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is not possible. But we need to check that entry_p->object_cp cannot be not NULL. Hm, but this could be a good idea. Since we only cache valid properties now, we could move the NULL to the property pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about it, and moving the NULL to prop_p is inefficient because the lookup() function depends on the object_cp. Here a (entry_p->prop_p == prop_p) check is not enough, since a property can be added, removed, and added to another entry position. This could work though:
if (entry_p->object_cp != ECMA_NULL_POINTER && entry_p->prop_p == prop_p)
But I think the difference is minor compared to the other one. I will try it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zherczeg, I see. Thanks for checking.
82a994d
to
2e6343f
Compare
} | ||
} | ||
} /* ecma_lcache_invalidate_row_for_object_property_pair */ | ||
return (size_t) ((ecma_string_hash (prop_name_p) ^ object_cp) & (ECMA_LCACHE_HASH_ROWS_COUNT - 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help me to understand this line. Maybe some comment would be good. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is randomizing the hash with the object. Before this patch, objects with the same field names evicted each other:
a[0] = 1; b[0] = 1; c[0] = 1; // c[0] evicted a[0] before. Not anymore
This happened frequently in access-fannkuch test. Now because the hash is xor-ed with the object, properties do not evict each other anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's tricky :) Great work!
Could we use the cache in |
LGTM |
2e6343f
to
bbd71ed
Compare
Actually ecma_op_object_put in vm_op_set_value has been recently optimized and already using it. But we could probably do something here as well in a follow-up patch. |
extern void ecma_lcache_insert (ecma_object_t *, ecma_string_t *, ecma_property_t *); | ||
extern bool ecma_lcache_lookup (ecma_object_t *, const ecma_string_t *, ecma_property_t **); | ||
extern ecma_property_t * ecma_lcache_lookup (ecma_object_t *, const ecma_string_t *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space after asterix
The cache stores only real properties now, because storing NULLs has little benefit according to tests. Since only real properties are stored now, there is no need to create real references to objects and property names, which reduces the keeping of dead objects after garbage collection. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
bbd71ed
to
5c852ab
Compare
LGTM |
The cache stores only real properties now, because storing NULLs has
little benefit according to tests. Since only real properties are
stored now, there is no need to create real references to objects
and property names, which reduces the keeping of dead objects after
garbage collection.