-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Perf Idea: Template Compilation Re-use #13915
Comments
Quite a few alternatives were discussed regarding performance improvements to the compiler. On top of the one @dcherman stated above, these (among many) were discussed:
In all cases, the biggest problem is that any change like this would be too big of a breaking change and would cause friction for people to upgrade to Angular's latest version. This does not mean that we cannot revisit some of these opportunities and put some effort into them, but that any work on this behalf does need some careful consideration. |
So I thought about my original idea more. The biggest downfall is the That means that we must always at least run the End users can still implement this optimization themselves where they have increased knowledge of how a directive is used and what should be allowed, but this is looking unlikely to be a library level optimization 😢 |
Out of curiosity, what are the concerns with making the linking process synchronous when templateUrl is used with a warm cache? I think I can make a strong argument that it may actually be preferable to do so in 1.5 as it may actually help address #13884. One of my co-workers should be posting a reproducer (kind of) with a writeup tomorrow from some debugging that we did, but I will add something to that issue if he doesn't since it's pretty late here now. |
The main issue is that directives authors that use About #13884, other options are in the table (none fully baked for 1.5). The main issue is getting a solution that has a consistent and predictable execution, and does not break the existing code. |
So if you look at #13884 (comment), you can actually see that even in existing versions, users are exposed to both sync and async behaviors due to how async directives are replaced with derived sync ones during the compilation process. As a result, you'll get different linking behavior right now if you have a simple parent -> child structure versus that same structure but with transclusion involved via something like Since I continue to assert that the common case (and best practice) is for people to pre-warm the template cache via a build step, making the template compilation synchronous would result in behaviors more similar to previous versions that didn't have lazy compilation. In either case, it looks like people cannot currently rely on linking order in any version. I generally recommend using controllers and |
I know about the current discrepancies, but the end goal for the compilation/linking to not have these discrepancies and simplify things for developers. I find that adding this synchronous |
Filing this for future consideration since this will be too big of a change to even think about considering it for 1.5.
One optimization that I've used with a lot of success in perf sensitive components is the re-use of the compiled template rather than letting the compile step re-compile the same template over and over again.
The basic idea is that once a template is compiled, you store that template under a cache that is keyed with the template string itself. As a result, you get to skip quite a lot of the work previously done in compile especially in directives that are composed together.
Generic Bag of Concerns:
compile
. This is the biggest consideration I've come up with so far; the compile function would modify the generated function for all future linking usage which is almost definitely not what you would want, however we can feature detect this by checking for the presence of a compile function and bailing out.The text was updated successfully, but these errors were encountered: