Comments (8)
It's the reflection between context.arguments and the named parameters that slows everything down.
If I replace this piece of code with only context.arguments = args;
then it works without additional slowness.
hooks/packages/hooks/src/base.ts
Lines 130 to 155 in 8762f76
From:
Baseline 20
Empty hooks 195
Single simple hook 268
Single hook and withParams 910
Single hook, multiple withParams 1531
Single hook, multiple withParams (no named) 250
To
Baseline 16
Empty hooks 180
Single simple hook 230
Single hook and withParams 232
Single hook, multiple withParams 365
Single hook, multiple withParams (no named) 221
from hooks.
That was my suspicion, too. Basically the Object.defineProperty
should happen once when the function is wrapped instead of every time it is run which makes a huge difference. I have some ideas on a more performant hook context initializer that does this, I will share it here when I gave it a test run.
from hooks.
I wonder if a Proxy (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Proxy) would be the solution?
from hooks.
Using a Proxy gives better results:
Baseline 15
Empty hooks 181
Single simple hook 202
Single hook and withParams 409
Single hook, multiple withParams 546
Single hook, multiple withParams (no named) 214
I opened a PR with that: #29
from hooks.
The other thing that slows down a lot is the Object.seal(context.arguments)
With Object.seal
:
Baseline 14
Empty hooks 174
Single simple hook 197
Single hook and withParams 476
Single hook, multiple withParams 462
Single hook, multiple withParams (no named) 177
Without Object.seal
:
Baseline 16
Empty hooks 130
Single simple hook 124
Single hook and withParams 283
Single hook, multiple withParams 292
Single hook, multiple withParams (no named) 128
jsPerf: https://jsperf.com/object-seal-freeze
from hooks.
My final result:
Baseline 14
Empty hooks 122
Single simple hook 128
Single hook and withParams 285
Single hook, multiple withParams 277
Single hook, multiple withParams (no named) 116
from hooks.
I started a branch in https://github.com/feathersjs/hooks/tree/dl/hook-manager to add to #22 and did some refactoring to see if there is room for improvements using a custom context class where things like argument names are defined once on the protoype instead of every function call. These are the results I am seeing with the benchmark at the moment:
Baseline 14
Empty hooks 120
Single simple hook 147
Single hook and withParams 143
I haven't had a chance to see if it plays well with feathersjs/feathers#1798 yet though.
from hooks.
Amazing, haven't you made the changes on decorator.js or is it an oversight?
The other thing is that the enumerable props and params are not really enumerable with getContextClass
.
from hooks.
Related Issues (20)
- Version 0.7.x fails to compile in Webpack HOT 3
- ERROR in ./node_modules/@feathersjs/hooks/esm/base.js 55:38 HOT 4
- Error hooks - re-throwing vs assigning context.error
- Allow to change the order of middleware HOT 2
- integrate it to existing feathers app HOT 7
- Combining multiple middleware with compose HOT 1
- API usage improvements HOT 1
- Brings webpack as dependency and many other due to that HOT 6
- Unable to add a context collector for all methods of an object HOT 1
- Turn .params, .props and .defaults into hooks HOT 2
- Order of multiple hooks: mismatch of documentation and behavior HOT 2
- Is it possible to remove a hook? HOT 2
- Wrong method name in context.method HOT 6
- Result and undefined HOT 8
- function.length is lost HOT 4
- Deno port chores HOT 1
- Error: Could not dynamically require "./base.js". HOT 3
- Notes on regular hooks support HOT 1
- Critical dependency: require function is used in a way in which dependencies cannot be statically extracted HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hooks.