Comments (8)
May I ask about your use-case? I'm just wondering if the performance hit is really noticeable at all (are we talking millions of validation calls per second?)
Just to add: a major use-case for typescript-is
is when you're running a server and you want to verify that a user-submitted request object is valid. This library is awesome for that, because it saves having to write lots of tedious validation code.
Since the validation is occurring on the hot path (for every request!), there is value in it being fast.
It would be very neat if there was an transformer option (which we could toggle for development-vs-production) that changed the behaviour of the assert*
functions to be "slow and helpful" or "fast".
A minimal solution would to be - as you have said - to make is
stop being slow. I'm having to stick with the older version due to this slowdown.
from typescript-is.
Here's a jsperf to illustrate this regression -- in v8 this code is ~1100x slower. Likely a good idea to revert this change, given that. Thanks all.
https://jsperf.com/typescript-is-changes-2
from typescript-is.
It's true that with the new generated the code there is a lot more complexity, becoming bigger in size and slower in run time performance.
The reason for it is so that the assert
family of functions can have much better error reporting.
I agree that this is unnecessary for the is
family of functions.
May I ask about your use-case? I'm just wondering if the performance hit is really noticeable at all (are we talking millions of validation calls per second?)
If necessary I can make the is
family of functions output simple Boolean expressions again, but it will take some work because I don't want to maintain two copies of the code (one for generating is
and one for generating assert
code) and I will need to insert some layer of abstraction to keep the logic unified.
Thanks!
from typescript-is.
@woutervh- Let me join this conversation. We have some use cases when we need to validate 100k+ data members in one step. Note that so far we don't know if the overhead required by validation would make a significant impact - just wanted to let you know that such large datasets are valid requirements in some cases.
from typescript-is.
hi @hernyo
Thanks for the info. I will see if I can make some time for performance improvements for the is
family of functions ;)
from typescript-is.
Hi, any chance this has been addressed? I checked through the release notes but didn't see anything mentioning it.
Thank you!
from typescript-is.
Unfortunately I haven't had the time yet to work on this, as it will take quite some time to complete.
Does this have a big impact on your project? If so, I'll consider it higher on the list of things to do.
from typescript-is.
Hi @woutervh-
I made this comment while looking for a library for typeguarding and was still deciding on one at the time. I have been using your library for the past couple days and wrote a test for how quick validation actually occurs, and it seems just fine to me. In my test, 100k is<MyInterface>(Object)
tests complete in less than 700ms. While previous releases might have run faster, I do not think the performance now is terrible or anything. My use case doesn't need nearly that many subsequent validations.
Now my problem is the fact that Date
types in interfaces break everything at run time, which I thought would not be the case with both "ignoreClasses": true
and "ignoreMethods": true
in my tsconfig.json
. I will be subsequently opening an issue on that now.
from typescript-is.
Related Issues (20)
- Feature Request: Shortcut to simplify `const v = func(); is<type>(v) ? v : default` HOT 1
- Fix intersections with primitives to add support for branded/flavored types HOT 1
- Intersection disables `disallowSuperfluousProperties` all the way down
- Non-deterministic code generated HOT 1
- Support typeof on object types
- Parsing fails when target & aliasTypeArguments are at different levels HOT 1
- Investigation of Unbound Type Parameters
- typescript-is introduces "typescript" dependency into production environment
- TypeError: Cannot read property 'text' of undefined
- Bug: A missing key and a key with a value of undefined are not considered the same
- Fail to check Enum in Record HOT 9
- Have you plan to support Deno? HOT 2
- use instantiation expressions in typescript 4.7
- Make generated code smaller by putting reusable strings to constants or functions HOT 1
- feature request: set custom error class in AssertType
- Thoughts on extending createAssertType() HOT 1
- Incompatible with TypeScript 4.8 HOT 2
- What about re-export `typia` for maintenance? HOT 1
- ttypescript not support TS@5
- Deprecation message and recommends to use `typia` instead 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 typescript-is.