angular icon indicating copy to clipboard operation
angular copied to clipboard

HTML escaper performance could be improved by adopting the same html escaping code as Svelte and Solid JS

Open cgranttm opened this issue 1 year ago • 1 comments

Which @angular/* package(s) are relevant/related to the feature request?

platform-browser

Description

The html escape function provided in @angular/platform-browser is outperformed by newer takes on it from Solid JS and Svelte. packages\platform-browser\src\browser\transfer_state.ts

Proposed solution

Consider adopting the same method as Svelte for escaping html. The code can be found here: https://github.com/sveltejs/svelte/pull/5701 Also here's a js bench comparing the two functions for store serialisation. I made a js bench comparing the old/new approach, it needs this gist to be in the setup data: https://gist.github.com/callumelgrant/dde6f54cd1544c1be5524a74b5365cd6 https://jsbench.me/uyl5xdwloa/1

Alternatives considered

It could be possible to make an even faster one than Svelte's.

cgranttm avatar Jul 23 '22 04:07 cgranttm

I made a draft PR for this https://github.com/angular/angular/pull/46951.

cgranttm avatar Jul 23 '22 04:07 cgranttm

For more context, here is the article discussing the issue and improvements: https://levelup.gitconnected.com/how-we-wrote-the-fastest-javascript-ui-framework-again-db097ddd99b6

And here is a PR with the improvement itself in SolidJS: https://github.com/ryansolid/dom-expressions/pull/27

pkozlowski-opensource avatar Aug 17 '22 12:08 pkozlowski-opensource

Closing as the escapeHtml method has been removed.

alan-agius4 avatar May 19 '23 13:05 alan-agius4

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.