brisa-build / brisa

The Web Platform Framework.
https://brisa.build
MIT License
449 stars 12 forks source link

perf: reduce client size 100 bytes and improve +1K ops/sec #626

Closed aralroca closed 1 week ago

aralroca commented 1 week ago

Related to https://github.com/brisa-build/brisa/issues/618

As we have discussed in this issue, we did a bad micro-optimization. The documentFragment does not go faster, besides it occupies more code.

By changing the implementation we reduced 100 bytes of client code and this operation goes from 12K ops/sec to 13k ops/sec (+1k). After this change, all current tests continue to pass the same.

Before:

current

Now:

proposal

https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment#performance

"The performance benefit of DocumentFragment is often overstated. In fact, in some engines, using a DocumentFragment is slower than appending to the document in a loop as demonstrated in this benchmark. However, the difference between these examples is so marginal that it's better to optimize for readability than performance." — MDN

tests

I assigned this PR to the issue because the idea was introduced here, although this does not fix the issue, it remains pending in the branch where I have the failing test of the issue. At least now we know it wasn't because of the documentFragment and there is something else to investigate.

pkg-pr-new[bot] commented 1 week ago

Open in Stackblitz

brisa-adapter-vercel

``` bun add https://pkg.pr.new/brisa-build/brisa/brisa-adapter-vercel@626 ```

brisa

``` bun add https://pkg.pr.new/brisa-build/brisa@626 ```

brisa-tailwindcss

``` bun add https://pkg.pr.new/brisa-build/brisa/brisa-tailwindcss@626 ```

brisa-pandacss

``` bun add https://pkg.pr.new/brisa-build/brisa/brisa-pandacss@626 ```

create-brisa

``` bun add https://pkg.pr.new/brisa-build/brisa/create-brisa@626 ```

www

``` bun add https://pkg.pr.new/brisa-build/brisa/www@626 ```

commit: ea99c0a