Skip to content

refactor(core): inline isFactory within getNodeInjectable#59824

Closed
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:refactor/core-NodeInjectorFactory
Closed

refactor(core): inline isFactory within getNodeInjectable#59824
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:refactor/core-NodeInjectorFactory

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

@arturovt arturovt commented Jan 31, 2025

This commit inlines the isFactory function body directly within getNodeInjectable because it is only used once. ESBuild does not inline its body within the function, which can be observed when running the build with NG_BUILD_MANGLE=0. The results after inlining are as follows:

getNodeInjectable x 70,397,377 ops/sec ±3.88% (52 runs sampled)
getNodeInjectable_inlined x 77,834,432 ops/sec ±3.13% (60 runs sampled)

Since isFactory is passed with different argument shapes, it never gets optimized.

The function is also used only once, so there's no reason to keep it separate, because in minified code it's function n(n){return n instanceof NodeInjectorFactory}.

@pullapprove pullapprove bot requested a review from crisbeto January 31, 2025 21:56
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Jan 31, 2025
@ngbot ngbot bot added this to the Backlog milestone Jan 31, 2025
@JeanMeche
Copy link
Copy Markdown
Member

JeanMeche commented Feb 1, 2025

Esbuild should theoritically inline the function. Maybe if we just move it to the same file this could be achieved ?

Edit: just checked, it doesn't.

@arturovt arturovt force-pushed the refactor/core-NodeInjectorFactory branch from 3ae2aae to 18de242 Compare February 19, 2025 06:54
@pkozlowski-opensource pkozlowski-opensource added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed action: merge The PR is ready for merge by the caretaker labels Feb 19, 2025
@pkozlowski-opensource
Copy link
Copy Markdown
Member

The isFactory is now also used in packages/core/src/render3/instructions/write_to_directive_input.ts so we can't do this refactoring.

@alfaproject
Copy link
Copy Markdown
Contributor

OOC, why not inline in both cases? The condition seems self explanatory. Are we improving readability that much by wrapping it in a function call?

@arturovt
Copy link
Copy Markdown
Contributor Author

@pkozlowski-opensource can you reopen the PR (I can’t do this), I will rebase and update another condition?

@JeanMeche JeanMeche reopened this Feb 19, 2025
@arturovt arturovt force-pushed the refactor/core-NodeInjectorFactory branch from 18de242 to a459aa4 Compare February 19, 2025 14:56
This commit inlines the `isFactory` function body directly within `getNodeInjectable` because it is only used once. ESBuild does not inline its body within the function, which can be observed when running the build with `NG_BUILD_MANGLE=0`. The results after inlining are as follows:

```
getNodeInjectable x 70,397,377 ops/sec ±3.88% (52 runs sampled)
getNodeInjectable_inlined x 77,834,432 ops/sec ±3.13% (60 runs sampled)
```
@arturovt arturovt force-pushed the refactor/core-NodeInjectorFactory branch from a459aa4 to f7bf09e Compare March 4, 2025 23:00
@pkozlowski-opensource pkozlowski-opensource added the action: merge The PR is ready for merge by the caretaker label Mar 5, 2025
@thePunderWoman thePunderWoman removed the request for review from crisbeto March 5, 2025 17:09
@mmalerba
Copy link
Copy Markdown
Contributor

mmalerba commented Mar 5, 2025

This PR was merged into the repository by commit 1124b8f.

The changes were merged into the following branches: main, 19.2.x

mmalerba pushed a commit that referenced this pull request Mar 5, 2025
This commit inlines the `isFactory` function body directly within `getNodeInjectable` because it is only used once. ESBuild does not inline its body within the function, which can be observed when running the build with `NG_BUILD_MANGLE=0`. The results after inlining are as follows:

```
getNodeInjectable x 70,397,377 ops/sec ±3.88% (52 runs sampled)
getNodeInjectable_inlined x 77,834,432 ops/sec ±3.13% (60 runs sampled)
```

PR Close #59824
@mmalerba mmalerba closed this in 1124b8f Mar 5, 2025
@arturovt arturovt deleted the refactor/core-NodeInjectorFactory branch March 5, 2025 17:32
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants