-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overthink dependency injection, performance and more (feedback) #12620
Comments
I'd like to take time to address each of these as I'm able to, and want to provide a way to actually have a discussion around these points. If I skip over one of your points, I either don't have a response at the moment, or will probably need more time to work out what I want to say about it.
Now, out of those, only C, in my opinion, should stay open so that it can be better tracked, but when people abuse the notification system by sending "+1" replies or "I need this", it makes it really hard to justify keeping them open as it generates a lot of noise in day to day life. Sure, if the feature was implemented faster people wouldn't do that, but it's open source, and we, as developers, have lives outside of providing features all day every day. If a feature would be that immensely useful, make a PR and try to help with it.
I'm curious as to what you mean by this, or why you would like to remove it in the first place, but I believe it goes back to
Kamil isn't the only person working on Nest, he's just the creator and the dev with the most experience. Myself, @micalevisk, and @Tony133, are all pretty active in the issues and Discord providing what support we can and reviews for PRs from community members, or providing new features when they're within our realm of possibility. We honestly love to see community contributions.
And I'll answer this with what I've answered before: if someone wants to write a Nest for Deno, great. But we will not be re-writing Nest to officially work in runtimes other than Node. I believe Bun is close to working with Nest out of the box, which is awesome, but we will not be re-working Nest for either Deno or Bun's sake. |
By the way, I just created this PR to solve the issue of microservices not being able to be configured using the |
here's the POC I made as an attempt to avoid the
|
Regarding the DI I was thinking to find a totally different approach by thinking out of the box. For example in Angular services (classes with
Something else that Angular did, which also might be interesting to consider for NestJS, is the remove of modules. An Angular standalone app does not require any modules anymore, but can still work with modules (for backwards compatibility). The standalone components (in our case probably the controllers) define what they want to import and the Angular compiler does the "magic" of putting it all together and treeshaking what is not used. I dont know if this are options for Nest but just thinking of Nest without the need to register injectables and without modules sounds like a dreamy wonderland to me. Anyway maybe these are some example of what I was thinking of a very different DI approach. Regarding serverless functions: I would LOVE to use it for serverless functions because of the structure that NestJS provides and the tools like controllers with dto validation, pipes, guards, etc. etc. - I dont know what is happening that takes so long when NestJS starts an empty standalone app. Maybe it is naive to ask if this things cant be all together removed, tree shaked or at least be simplified? Cant Nest become more lightweight? (Ronny Coleman would probably approve) Regarding closing issues for example on #2343 I wanted to add another solution for anyone else to come (Profiguration) but comments are locked. And this happened to me dozens of times in the last years. |
Angular has a compiler and I'm pretty sure they have a huge team that is paid to maintain the project. So I think we just can't introduce things like that in Nestjs Also, since providers doesn't need to be annotated with Personally, I don't like magic when working with nodejs. I like to know what things are doing because it's easier to understand if you have a good background on Nodejs. |
Isnt abstraction one of the key purposes of a framework like NestJS? The more I think about it the more I like the idea of removing modules + adding auto injection which both could increase both the developer experience as well as the cold start speed. I understand NestJS doesnt have a big team and budget like Angular has. |
Nest does a lot of abstractions, but all of the wiring is still explicitly there, which is what micalevisk is referring to here (I believe, correct me if I'm wrong). The
It's finding all the classes that have |
Those abstractions are fine. Although I feel that nestjs has a lot of them already. I was talking about CoC. I can't think of one that would be both flexible and easy to learn
I still don't know how that is supposed to work in practice. |
A lot of things can slow down your startup, like:
To be honest, it's only a problem after 1s, Also, one thing that you can do to optimize the startup time in your serverless runtime is to use the correct libraries, I'm the maintainer of Serverless Adapter and if you use my library, you can save up to |
Hi all, Regarding this discussion I agree with what @jmcdo29 , @micalevisk and @H4ad have already said. I just want to focus on a few points: 1)As for the documentation, which is often talked about and discussed, but have you looked at the available documentations? Are they better than the NestJS one? Anyone who wants to improve it is free to create a PR by editing the texts. But many times in my opinion it is because you read too fast and some concepts are not understood right away because you have to have time to experiment even via code. Then like all documentation you have to "explore" it to see how it is divided, and see the various chapters and sections. In short, you have to spend the right amount of time studying, personally I have seen much worse documentation than NestJS. The only thing I hope is that dark mode is added soon so I can view it without using browser plugins to darken it. Especially for those with light eyes like me, it's a bit annoying to look at it in the evening. (See PR here nestjs/docs.nestjs.com#1138) I also want to tell you in advance that I will soon open an issue with all the PRs already approved and some issues that we can close in the documentation repository, so as to make everything even more visible to Kamil and the members of the main team. I hope to do it next weekend
At the moment I will share these points with you, then if I have more I will write to you Have a great week everyone! 😉 |
I won't refer to every point myself as I fully agree with everything that has been already said by @jmcdo29, @micalevisk, @H4ad, and @Tony133 above. R1. Why would you want to use R2. I just realized that R3. We should improve the documentation and make it more clear on how to achieve type safety with
They could "just work" in Nest too, but we decided to go with the explicit approach. Angular team decided to drop the explicit approach because it made perfect sense given what challenges they were facing (tree shaking, lazy loading), and also the specific nature of the framework (their DI implementation was simply different and behave differently). We don't have to follow the same path as we don't run into the same issues.
Same here. This makes zero sense for Nest apps. R4. I don't understand how introducing such a massive breaking change would be beneficial for the community. R7. Contributions are more than welcome. Some folks say that NestJS are the best out there, some think & say the exact opposite. It is what it is I guess. |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
I am working full time with NestJS in the past 4+ years but every time I start a new project some things get me very frustrated:
The only workaround is to create another app before this app just to get the ConfigService but this will also double connections to MongoDB, microservice server, Redis, etc. which is especially not acceptable for serverless functions. Open issue from 2019: #2343
ConfigService
in the@Module()
decorator is always a pain, or better said any timeuseFactory()
is needed is a pain. And it gets worse when dealing with injection tokens:The creation of a ConfigService itself is painful as well when wanting to have validation and type safety. There is no clear path showed in the docs, and the documentation about this topic is very very long. It would be great if NestJS provides a more opinionated ready-to-use solution that is easy to setup and use and provides auto completion and type safety.
The docs and the naming conventions are focused mainly on NestJS as a Http API. For example a "controller" currently always refers to a Http-Controller. In contrast most of the apps I developed for different companies are microservices that only provide Ms-Controller and no Http API. IMO this distinction should be made more clear throughout the docs (which most developers take as best practices) as well as in the code and cli. For example the file naming convention could be
cat.http-controller.ts
/cat.ms-controller.ts
and the CLI could have two command:g ms-controller
andg http-controller
. Also the creation of a new app could be more clear, currentlyNestFactory.create()
creates a HttpApp,NestFactory.createMicroservice()
creates a MS app, andNestFactory.createApplicationContext()
creates a standalone app. Why not rename it accordingly, e.g..createHttpApp()
,.createMicroserviceApp()
and.createStandaloneApp()
?Make the fastest options the default. E.g. when Fastify is really 2x faster than Express, why is it not the default? If SWC if 20x faster than TSC, why is not the default?
Startup time of the app is way too long, especially for use with serverless functions. According to the docs Express takes 7.9 ms for startup and NestJS with Express takes 197.4ms which is 26x slower. I wonder why that is the case and if we can get close to where Express is? Even without Express it takes 111 ms to create an empty Nest standalone app.
The docs are very long and hard to read. They dont have a particular order and specific topics are hard to find. A lot of features can only be found by clicking through each page and seeing what is behind. E.g. I only know about "SWC" because one day I decided to click through all "recipe" pages.
Github issues always get locked for discussion. Countless times I googled and found an old issues where someone had the same problem like me. Often I had useful informations to add to those issues or maybe even found a solution that is not mentioned there but I cant add this informations for anyone else coming to this issue in the future. I also have the feeling that discussions or feature requests are often just cut off.
Describe the solution you'd like
Most of my frustration comes from the dependency injection and the config service and I wonder if the DI can be fully reworked and/or simplified to address faster startup time and remove the need of async useFactory() functions for modules as well as make it possible to use the configService in the main.ts.
Also I have the feeling that it effects the framework in a negative way that it is fully managed by just one person. It might be beneficial for NestJS to open up more for the community to contribute, give feedback and make decisions.
Offtopic: What about Deno? :)
Teachability, documentation, adoption, migration strategy
What is the motivation / use case for changing the behavior?
The text was updated successfully, but these errors were encountered: