Skip to content

Optimize keyword argument methods using call-target-specific arguments #2388

Open
@wildmaples

Description

@wildmaples

Background

Keyword arguments are being used more often and we'd like to optimize it. There was a previous implementation that was reverted but we're trying to re-implement as according to the paper, Call-target-specific Method Arguments, but possibly a little more simply.

The specific method arguments we are targeting are the methods with keyword arguments without any rest arguments, which is 0.03% of dynamic method calls. However, that only includes internal/core method calls. So we ran a benchmark on storefront-renderer to see the percentage of method calls that can be optimized per request and it seems like it comes to a low percentage -- 0.56% of total dynamic method calls can be optimized in this case.

However, we agreed that this change is worth doing because it doesn't require too much effort, it's forward thinking, and it should be relatively easy to do. What do you think?

Implementation

The optimization boils down to saving on the allocation of a hash for the keyword arguments case. Typically, a hash would be created to store the key-value pairs and then passed to the callee to unpack, meaning the hash always escapes if the call is not inlined.

Our goal is to optimize that process by evaluating, flattening, and then packaging the arguments into the argument array that'll be passed to the callee. A marker will be added to inform the callee if the packed argument array is expandable/optimized. With that, we'll also need a map of the index for the location of each of the arguments in the array. When the callee receives the arguments, it'll unpack the arguments based on the index map.

So an argument hash won't have to be allocated per call. Additionally, we can polymorphic inline cache the method lookup based on the types of arguments passed to the callee.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions