Skip to content

Performance implications of composing templates #4124

Answered by AndrewJakubowicz
MrHBS asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! Great question! I wouldn't be too concerned. I can talk through some performance thoughts about your two cases.

Case 1: Abstracted template:

html`${this.headerTemplate()}`;

Case 2: Inlined template:

html`<header>${this.article.title}</header>`;

The performance difference is very similar to a raw JavaScript case. In case 1, there is an additional method call, dynamic value binding, and an additional html template. These are all very cheap but will create a tiny overhead.

In Case 2, we've removed these tiny overheads, but lost flexibility.

The answer is – it depends on your application. Abstraction and flexibility in JavaScript always come with a tiny performance penalty.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@MrHBS
Comment options

@augustjk
Comment options

Answer selected by MrHBS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants