Conversation
|
I didn't think this was a good idea when I started hearing interest in using it for GLPI back in November 2024, and I still don't. My opinion of live components is even worse. They simply don't make sense for a real, complex, non-public web application to me and it isn't clear from the roadmap entry just how far this is going to go. Certainly the plan isn't to add all of this only to render alerts? I don't see what this accomplishes besides adding more layers of abstraction and ✨ magic ✨. Maybe you could say it adds encapsulation, but it doesn't seem any better than what the original macros did. Alerts are so trivial that this doesn't show anyone how well or poorly this kind of solution would scale with anything but the simplest of components. Testing a Twig template with: {% for i in 1..100 %}
<twig:Alert:Danger>Danger alert</twig:Alert:Danger>
{% endfor %}took about 20ms to render (sometimes up to 40) even without debug/development mode enabled while the raw HTML in the template: {% for i in 1..100 %}
<div class="alert alert-danger" role="alert">
<div class="d-flex">
<div class="me-2">
<i class="ti ti-exclamation-circle fs-2x alert-icon"></i>
</div>
<div>
Danger alert </div>
</div>
</div>
{% endfor %}took under 1ms consistently. Another comparison is with the original macros which takes just 4-8ms: {% import 'components/alerts_macros.html.twig' as alerts %}
{% for i in 1..100 %}
{{ alerts.alert_danger("Danger alert") }}
{% endfor %}A quick comparison in Vue rendering 100 Message components from PrimeVue (which are actually more customizable) took 12-14ms in development mode and 5-8ms in production, which makes it about as fast as SSR with Twig macros. Once a lot of components are being used, especially nested, the performance overhead is going to be more of an issue. Finally, options for testing these components remains PHPUnit doing HTML parsing or E2E loading a full, slow GLPI page. With Vue, there is the option of a component test that mounts just the component(s) being tested in a real browser. In order to even start convincing me of using twig components, I would need to see a more consequential use of then in something like the ticket timeline, datatables (with the pagination, sort and filter functionality), search or kanban. |
|
@cconard96 This was seen and discussed with @cedric-anne and @orthagh. The goal is to remove macro for easier and more readable components enhancing the DX. |
|
Please @cconard96, This pr doesn't mean we are fullly rewriting GLPI with Twig components, just cleaning a few quircks in the existing codebase. For the moment, with new interns, we need to build correctly the team to continue our progression. I appreciate your tests with your personal side-project and follow a bit the thing, but this has not been approved as an official project. |
Its not just that I am convinced of the latter. I want GLPI to be more maintainable, performant, and offer benefits to users no matter which direction we go. Part of that is not seeing something simple like a Twig alert macro being abstracted away making it slower for little if any benefit. Also the roadmap entry only talking about Alerts made me worried the scope was very limited. Adding another way to render HTML to GLPI just for alerts seems unnecessary and adding this for a lot of things could bring the performance concerns I outlined. Obviously I take a lot of pride in my Vue work (and most of the work I do for GLPI as a whole), but I clearly haven't abandoned the current frontend. I've been trying my best to make improvements within the restrictions of the current design even as I work on something I'd like to see replace it. If my only opinion was that "my solution is right" I wouldn't be trying to fix what is already in use. |
|
With a huge application like GLPI, the "single responsibility" concept, combine with clear code structure, is very important to give the ability to developers to easilly locate the code responsible of something they want to fix/enhance. It is also mandatory if we want to be able in the long term to split the GLPI code into application modules. Twig components, combined with the dependency injection, may help a lot to have standalone components with their own class+template. |
|
I think we will have to agree to disagree on the ease of locating responsible code (Symfony plugin doesn't even seem to properly support them in PHPStorm) at least with what I saw so far, especially for new contributors and plugin maintainers that aren't fully aware of GLPI's code and the Symfony Framework as a whole. I suppose there is a benefit for hired developers if Teclib' specifically hires PHP developers with Symfony experience. Nevertheless without seeing how this works out with something more complex my opinion of it has shifted to neutral. Not ideal, but not terrible as long as it isn't overused and the performance impact should be kept in mind. If more logic shifts to inside the component classes, developers should be careful not to over-fetch or fetch duplicate data when possible since nothing is cached. It is already an issue with the current Twig setup, but there are cases where an array of items is given to the template all at once. It could be worse like this if each component fetches the data it needs separately. |
cedric-anne
left a comment
There was a problem hiding this comment.
Could you split this into two distinct PRs ? I would like to focus on the integration of Twig inside the dependency injection system. Once merged the Twig component part would be pretty simple to validate.
If I understand things correctly, common UI items like drodowns are not the best candidates to be a twig component due to high performance impact compared to simple twig files (we have pages with tons of dropdowns like the form editor that definitively do not need to get slower than they already are). |
|
Looking into doing the split for the integration of Twig inside the dependency injection system (will be in another PR) FYI, I ran a quick test with 1000 Alert on 4 types (you can find detailed datas and info in the outline) : Performance SummaryThe following table aggregates the average execution times (in milliseconds) for 1,000 iterations:
For Twig component, first Alert generation took on average .38ms and the 999 other alerts take .07-.06ms to render. So having a lot of component on the page could even neglect the performance difference with macro. |
So, nothing |
84fc85f to
4eeff35
Compare
|
Failing tests are due to the deprecation message I've added. It was planed to do a simple PR here and to the migration on another PR for all the Alert calls in core but maybe it should be done in this one so ? (or I remove for now the deprecated log ??) |
Just comment the call to |
|
LGTM looking at th code. Please rebase to solve conflicts. Tests are currently failing. |
550e6d3 to
d0bfacf
Compare
d0bfacf to
214d2d1
Compare
Checklist before requesting a review
Please delete options that are not relevant.
Description
This PR add the support of Twig Component with autowiring support
(another branch is created simpler but use flagged@internalTwigComponents - Diff between this PR and the one without autowire froozeify#6)Documentation
Roadmap