Benzinga / lz4js

Lz4 for the browser.
89 stars 21 forks source link

decompression performance improvements (~50%) #4

Closed ledbit closed 6 years ago

ledbit commented 6 years ago

Two main reasons for perf gains:

  1. use TypedArray.copyWithin
  2. use TypedArray.subarray which reuses buffer instead of TypedArray.slice which makes a copy (and thus more work + GC)

Decompress a 12MB file, representing 100MB of raw data orig: 230ms copyWithin15+: 145ms subarray: 130ms copyWithin31+: 120ms lz4cat: 70ms

codecov-io commented 6 years ago

Codecov Report

Merging #4 into master will decrease coverage by 1.01%. The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #4      +/-   ##
==========================================
- Coverage   94.75%   93.73%   -1.02%     
==========================================
  Files           3        3              
  Lines         343      351       +8     
  Branches       41       45       +4     
==========================================
+ Hits          325      329       +4     
- Misses         18       22       +4
Impacted Files Coverage Δ
lz4.js 91.69% <60%> (-1.3%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bab5b9f...e51316b. Read the comment docs.

jchv commented 6 years ago

Ah, I missed this - looks pretty good.

Do you think the hasCopyWithin check is sufficient? Do any browsers have partial support for these functions? I am pretty sure the last time I was messing around, I found that browser support for Typed Arrays was oddly inconsistent.

In any case, I'm interested in merging this either way.

(I probably should test this across a few browsers first, though.)