-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Performance issues when escaping looooong value as html_attr
#4322
Comments
inside quoted attribute values, it is safe to use the The |
Indeed, I've reverted my code and used Thanks @stof! |
@stof could you please explain a bit more what do you mean by "unquoted values"? Maybe show an example? The Twig docs (https://twig.symfony.com/doc/3.x/filters/escape.html) say this:
|
@javiereguiluz HTML does not force you to put quotes around values of attributes. The attribute context is the context where you write those attributes. Looking at the HTML parsing state, it has several state related to parsing attribute pairs: https://html.spec.whatwg.org/#before-attribute-name-state (sections 13.2.5.32 to 13.2.5.39) |
We should maybe clarify the docs? Who wants to give it a try? |
Thanks a lot for the details @stof 🙏 |
…erformances by switching to `html` escaping strategy (Kocal) This PR was squashed before being merged into the 2.x branch. Discussion ---------- [StimulusBundle] Improve `StimulusAttributes` rendering performances by switching to `html` escaping strategy | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> A better alternative to #2178, by changing the escaping strategy for HTML attributes value from `html_attr` to `html`, as indicated by `@stof` in twigphp/Twig#4322 (comment). On my use case (a `Map` with 1000 `Marker` and `InfoWindow`), [I have a performance gain of ~68%](https://blackfire.io/profiles/compare/56f4d7d2-ee56-487f-8a78-420f4037165f/graph): <img width="1057" alt="image" src="https://github.com/user-attachments/assets/8b7ff48d-8e6e-4dae-b09e-2c323bc2449d"> This PR should also improve performances of our packages using the `StimulusAttributes` DTO, like Chart.js, LiveComponent, ... --- > [!IMPORTANT] > The initial PR changed a bit, the default rendering strategy does not change, but instead we introduce a new configuration to use the new (and optimized) rendering strategy, see #2180 (comment). Commits ------- 647532a [StimulusBundle] Improve `StimulusAttributes` rendering performances by switching to `html` escaping strategy
Hi everyone, sorry if this issue is a duplicate, but I didn't find anything here.
For reference: symfony/ux#2178
With Symfony UX Map, when you create a Map with 1000 Marker and InfoWindow, the following code takes ~62% of the response time (near ~220 ms) to escape
$string
(here, a big JSON object which have been stringified):Twig/src/Runtime/EscaperRuntime.php
Lines 240 to 303 in 126b2c9
I.. don't know if its more an issue from Twig or a skill-issue from our
StimulusAttributes
usage.But do you think something is optimizable here? is it safe to replace
'a very long stringified json object'|e('html_attr')
withhtmlentities(json_encode('...')
? Because this combo improved performances by 62%!Thanks!
The text was updated successfully, but these errors were encountered: