Consider supporting Proxy
In https://github.com/facebook/hermes/blob/master/doc/Features.md Proxy is listed as Excluded From Support. With
Hermes plans to target ECMAScript 2015 (ES6), with some carefully considered exceptions.
What are those considerations regarding Proxy?
Especially some library in JS environnement like:
- mobx 5
- immer rely on proxy support. It is super usefully to add observability upon an object access which helps building reactive apps.
Would it be technically possible to have support as an external / optionnal *. aar so it does bot affect the size of hermes ?
Solves:
- https://github.com/facebook/hermes/issues/28
I think this is a very important feature! After Redux, MobX is the most used state management solution with React which is getting more popular every day.
Not only that, many state management libs are based on proxy, such as react-easy-state, and many other include Immer, such as easy-peasy.
It seems there is a misconception that Immer or Mobx absolutely need proxy to work which is not true.
https://twitter.com/mweststrate/status/1150138659909361665
They're not required, but performance with proxies is significantly faster than with JS getter/setter properties. That, and non-proxy builds have some pitfalls that don't exist in proxy builds.
For helping prioritizing, does anyone have data that shows popular apps / libraries are performing badly without this? Just like any team, prioritizing features and resources is critical.
@lishine, do you have a list? the more data and targeted we can be, the more we can measure
Performance comparison aside, the bellow state management libs do not use immer, they rely on proxy and symbols, I have used them or considered to use, and there are many more: react-easy-state parket react-recollect
Of course they are not big sharks like mobx, but are useful for their size, speed, simpliness and easiness.
We too rely on Proxy for a small chunk of our infrastructure. -- Before JSC supported it, we wrote a micro-ponyfill that sort of implemented some of the features we needed. (It's impossible to Polyfill most of the Proxy API because it requires low level engine support). It had so many caveats that we did not publish this as open-source.
It would definitely be ideal if Hermes added support for this API! -- We don't need the full Reflection API / I don't think I even understand what that would entail, but Proxy is super powerful on its own.
+1. Proxy support would be great to have as well. We decorate our data models with a Proxy caching layer to speed up computations. We're also intending to upgrade keep up-to-date with mobx, but lack of support in hermes would bar us from doing so
+1 - MobX aside, proxies are incredibly useful constructs that we want to use directly in our own code and cannot while using Hermes.
I'm working on crypto projects and ethereum js uses Proxy. Support for this on hermes would be highly desireable
Proxies allow for a somewhat cleaner API when inspecting and debugging e.g. with mobx v5. This would be awesome to have.
@crutkas
Regarding performance benchmarks:
From the Immer docs
The ES5 fallback implementation is roughly twice as slow as the proxy implementation, in some cases worse.
Considering the operations are generally very quick anyway, this doesn't seem like the biggest deal in the world. That being said, I think proxy support would be a fantastic addition to Hermes. As proxy support in general becomes more widespread, I think we will see more and more libraries taking advantage of them, and potentially even omitting support for non-proxy environments all together. It would be a real shame to be locked out of certain parts of the ecosystem because one aspect of your JS runtime couldn't support it.
All of that being said, this is a really cool project and thanks for working on it!
*Unfortunately I have yet to find any benchmarks on MobX4(non-proxy version) vs MobX5(proxy version).
I have used a library that uses mobx5, but when I install on my project with hermes I need to make manual change to mobx4 on yarn.lock, etc This is complicated, because can on future come more libraries using proxy and with hermes will be impossible to use.
Please consider proxy support.
To keep the engine’s size small, we have chosen not to support a few language features that do not appear to be commonly used in React Native apps, such as proxies (...) — Source
I believe this is a very dishonest take, considering the support for proxies was broken for Android since forever so people were coming up with workarounds to avoid using them in the first place
Proxy allows for a whole realm of capabilities, previously impossible in javascript. By blocking it because its "underused" is preventing those capabilities from being explored.
The ability to analyze which properties a function accesses has some great advantages. Currently we use it to know exactly which parts of our state to persist on redux state changes.
We don't use it in any type of situation where it would create a performance problem. Both the claims for not implementing (underuse, performance) are invalid.
I’d like to explain a little more about our thoughts on Proxy. Our concern is that Proxy inserts itself into the JS engine in many places. In an interpreted engine like Hermes, this adds overhead, even if Proxy is never used. For example, when looking up a property on an object, now Hermes needs to check on every call if the object is a Proxy, and branch to a separate code path, even if this branch is never taken. This is not a large cost, but it happens very, very often. Even a little extra cost repeated many times can add latency, even with CPU branch prediction. There are also performance improvements we’d like to investigate which use static analysis of the JS code, but with Proxy, static analysis becomes much harder.
That said, it would appear that our evaluation of the use of Proxy was inadequate. We looked at Facebook RN apps (of which there are many), and FB does not use any of the packages in common use in the community which depend on Proxy. This led us to believe Proxy wasn’t important, but it is now one of our most requested features.
We have begun to investigate how we can implement Proxy without significant impact to performance, and we hope we can build something which meets the needs of the community. But, since we hadn’t originally planned on doing this work, it’s a low priority task, so we can’t give any estimate when Proxy would be available for Hermes. We ask for your patience as we investigate the best way to move forward.
@mhorowitz thanks for providing the explanation. I'm a bit out of my depth with how the VM works, but curios... Is similar branching already happening with computed properties like getters? To me it seems like a similar scenario where you have to execute some code when a property is accessed.
Yes, property accessors also require branching, and we've been careful to minimize those costs. We can overlap the checks in some places, due to the nature of C++ bit comparisons, but not everywhere. Mainly, proxies modify a lot more code paths than accessors do. For example, there's no accessor equivalent to the ownKeys and getOwnPropertyDescriptor traps, and these end up affecting the behavior of a surprising amount of the system.
@mhorowitz I'm not a totally versed on VMs but would it not be possible to put Proxy behind some sort of flag? I'm sure some people wouldn't mind opting into the performance hit for improve DX w/ proxies
It would be possible to make it a build flag, but this creates long-term support issues. Flags combine to describe a exponential number of builds. So either everyone need to build the VM from source to set the flags they want, which complicates integration, or we need to create an ever-increasing number of binary releases to support combinations of flags. So this is not a first-choice strategy.