object = {
value: 'data'
};
proxy = new Proxy(object, {})
proxyWithHandler = new Proxy(object, {
get(target, prop, receiver) {
return target[prop];
}
})
object.value;
proxy.value
proxyWithHandler.value
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object access | |
Proxy access | |
Proxy with get handler access |
Test name | Executions per second |
---|---|
Object access | 14537987.0 Ops/sec |
Proxy access | 8755823.0 Ops/sec |
Proxy with get handler access | 5896575.5 Ops/sec |
Let's break down the benchmark and its options.
Benchmark Overview
The benchmark measures the performance of accessing properties on an object using three different approaches:
Proxy
with a custom handler)Direct Object Access
This approach accesses the value
property directly on the object
instance.
Pros: Simple and straightforward, no additional overhead. Cons: May involve unnecessary computations or checks if the property exists.
In this benchmark, the direct object access is used to measure the performance of accessing properties on an object without any modifications. This allows us to compare the baseline performance of the JavaScript engine.
Proxy Access (without reflection)
This approach creates a new Proxy
instance that wraps the original object
. The get
trap is not defined, so it will follow the "default" behavior for property access.
Pros: Allows for more control over property access and computations. Cons: May introduce additional overhead due to the creation of the proxy instance and setting up the traps.
In this benchmark, the proxy access without reflection measures the performance of accessing properties on a proxy object that has not been customized with a specific get
trap. This helps us understand how the JavaScript engine handles default behavior for property access on proxies.
Proxy Access with Get Handler
This approach creates a new Proxy
instance that wraps the original object
. The get
trap is defined to simply return the value of the target property.
Pros: Allows for more control over property access and computations. Cons: May introduce additional overhead due to the creation of the proxy instance and setting up the traps.
In this benchmark, the proxy access with get handler measures the performance of accessing properties on a proxy object that has been customized with a specific get
trap. This helps us understand how the JavaScript engine handles custom property access on proxies.
Libraries and Features
There is no library used in this benchmark. However, we should note that the Proxy
API is part of the ECMAScript standard and is widely supported across most modern browsers and platforms.
No special JavaScript features or syntax are used in this benchmark.
Alternatives
Other alternatives for measuring performance could include:
set
trap or a custom implementation.These alternatives could help us explore different scenarios and edge cases that might not be covered by this specific benchmark.