fix(core): not invoking object's toString when rendering to the DOM #39843
Conversation
AndrewKushnir
reviewed
Nov 25, 2020
fbebcd5
to
9488506
9488506
to
29f855d
Currently we convert objects to strings using `'' + value` which is quickest, but it stringifies the value using its `valueOf`, rather than `toString`. These changes switch to using `String(value)` which has identical performance and calls the `toString` method as expected. Note that another option was calling `toString` directly, but benchmarking showed it to be slower. I've included the benchmark I used to verify the performance so we have it for future reference and we can reuse it when making changes to `renderStringify` in the future. Also for reference, here are the results of the benchmark: ``` Benchmark: renderStringify concat: 2.006 ns(0%) concat with toString: 2.201 ns(-10%) toString: 237.494 ns(-11741%) toString with toString: 121.072 ns(-5937%) constructor: 2.201 ns(-10%) constructor with toString: 2.201 ns(-10%) toString mono: 14.536 ns(-625%) toString with toString mono: 9.757 ns(-386%) ``` Fixes angular#38839.
29f855d
to
4893f2b
mhevery
approved these changes
Nov 30, 2020
|
FYI, adding "risk: medium" to indicate that it might make sense to land it as a separate CL in g3. |
mhevery
approved these changes
Nov 30, 2020
reviewed-for: global-approvers
jessicajaniuk
added a commit
that referenced
this issue
Nov 30, 2020
…39843) Currently we convert objects to strings using `'' + value` which is quickest, but it stringifies the value using its `valueOf`, rather than `toString`. These changes switch to using `String(value)` which has identical performance and calls the `toString` method as expected. Note that another option was calling `toString` directly, but benchmarking showed it to be slower. I've included the benchmark I used to verify the performance so we have it for future reference and we can reuse it when making changes to `renderStringify` in the future. Also for reference, here are the results of the benchmark: ``` Benchmark: renderStringify concat: 2.006 ns(0%) concat with toString: 2.201 ns(-10%) toString: 237.494 ns(-11741%) toString with toString: 121.072 ns(-5937%) constructor: 2.201 ns(-10%) constructor with toString: 2.201 ns(-10%) toString mono: 14.536 ns(-625%) toString with toString mono: 9.757 ns(-386%) ``` Fixes #38839. PR Close #39843
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


Currently we convert objects to strings using
'' + valuewhich is quickest, but it stringifies the value using itsvalueOf, rather thantoString. These changes switch to usingString(value)which has identical performance and calls thetoStringmethod as expected. Note that another option was callingtoStringdirectly, but benchmarking showed it to be slower.I've included the benchmark I used to verify the performance so we have it for future reference and we can reuse it when making changes to
renderStringifyin the future.Also for reference, here are the results of the benchmark:
Fixes #38839.
The text was updated successfully, but these errors were encountered: