Fast, reliable Reed-Solomon erasure coding as a native addon for Node.js.
JavaScript C++ Python
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md Update README Apr 16, 2018
benchmark.js
binding.cc
binding.gyp
package-lock.json
package.json
test.js

README.md

reed-solomon

Fast, reliable Reed-Solomon erasure coding as a native addon for Node.js.

For a good introduction to erasure coding, see this post by Brian Beach on the Backblaze blog.

License

reed-solomon is licensed under the MIT License.

Installation

npm install @ronomon/reed-solomon

Performance

The native addon executes asynchronously in Node's threadpool without blocking the event loop:

       CPU | Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz
     CORES | 8
   THREADS | 1

------------------------------------------------------------------
      DATA |     PARITY | SHARD SIZE |    LATENCY |     THROUGHPUT
------------------------------------------------------------------
         1 |          1 |       4096 |    0.181ms |     22.58 MB/s
         1 |          1 |       8192 |    0.016ms |    509.78 MB/s
         1 |          1 |      16384 |    0.014ms |   1130.00 MB/s
         1 |          1 |      32768 |    0.017ms |   1906.00 MB/s
         1 |          1 |      65536 |    0.022ms |   2991.81 MB/s
         1 |          1 |     131072 |    0.044ms |   2994.59 MB/s
         1 |          1 |     262144 |    0.091ms |   2888.98 MB/s
------------------------------------------------------------------
         1 |          2 |       4096 |    0.013ms |    324.68 MB/s
         1 |          2 |       8192 |    0.014ms |    593.47 MB/s
         1 |          2 |      16384 |    0.015ms |   1067.74 MB/s
         1 |          2 |      32768 |    0.020ms |   1642.25 MB/s
         1 |          2 |      65536 |    0.039ms |   1691.72 MB/s
         1 |          2 |     131072 |    0.085ms |   1537.05 MB/s
         1 |          2 |     262144 |    0.144ms |   1821.81 MB/s
------------------------------------------------------------------
         1 |          3 |       4096 |    0.026ms |    160.08 MB/s
         1 |          3 |       8192 |    0.031ms |    268.54 MB/s
         1 |          3 |      16384 |    0.035ms |    473.59 MB/s
         1 |          3 |      32768 |    0.042ms |    775.71 MB/s
         1 |          3 |      65536 |    0.055ms |   1182.15 MB/s
         1 |          3 |     131072 |    0.103ms |   1274.90 MB/s
         1 |          3 |     262144 |    0.181ms |   1451.16 MB/s
------------------------------------------------------------------
         1 |          4 |       4096 |    0.034ms |    120.92 MB/s
         1 |          4 |       8192 |    0.032ms |    255.86 MB/s
         1 |          4 |      16384 |    0.038ms |    435.96 MB/s
         1 |          4 |      32768 |    0.046ms |    714.41 MB/s
         1 |          4 |      65536 |    0.064ms |   1018.49 MB/s
         1 |          4 |     131072 |    0.120ms |   1091.67 MB/s
         1 |          4 |     262144 |    0.237ms |   1107.16 MB/s
------------------------------------------------------------------
         2 |          1 |       4096 |    0.031ms |    266.48 MB/s
         2 |          1 |       8192 |    0.030ms |    548.66 MB/s
         2 |          1 |      16384 |    0.099ms |    331.12 MB/s
         2 |          1 |      32768 |    0.072ms |    916.51 MB/s
         2 |          1 |      65536 |    0.062ms |   2124.06 MB/s
         2 |          1 |     131072 |    0.078ms |   3375.33 MB/s
         2 |          1 |     262144 |    0.101ms |   5213.68 MB/s
------------------------------------------------------------------
         2 |          2 |       4096 |    0.014ms |    583.78 MB/s
         2 |          2 |       8192 |    0.019ms |    854.26 MB/s
         2 |          2 |      16384 |    0.036ms |    922.31 MB/s
         2 |          2 |      32768 |    0.044ms |   1479.00 MB/s
         2 |          2 |      65536 |    0.064ms |   2063.50 MB/s
         2 |          2 |     131072 |    0.112ms |   2332.02 MB/s
         2 |          2 |     262144 |    0.256ms |   2051.73 MB/s
------------------------------------------------------------------
         2 |          3 |       4096 |    0.032ms |    253.42 MB/s
         2 |          3 |       8192 |    0.032ms |    513.28 MB/s
         2 |          3 |      16384 |    0.040ms |    826.87 MB/s
         2 |          3 |      32768 |    0.053ms |   1227.29 MB/s
         2 |          3 |      65536 |    0.084ms |   1561.73 MB/s
         2 |          3 |     131072 |    0.166ms |   1582.54 MB/s
         2 |          3 |     262144 |    0.303ms |   1728.07 MB/s
------------------------------------------------------------------
         2 |          4 |       4096 |    0.028ms |    293.28 MB/s
         2 |          4 |       8192 |    0.030ms |    547.30 MB/s
         2 |          4 |      16384 |    0.039ms |    840.73 MB/s
         2 |          4 |      32768 |    0.056ms |   1177.14 MB/s
         2 |          4 |      65536 |    0.099ms |   1326.55 MB/s
         2 |          4 |     131072 |    0.172ms |   1523.45 MB/s
         2 |          4 |     262144 |    0.410ms |   1278.81 MB/s
------------------------------------------------------------------
         3 |          1 |       4096 |    0.029ms |    420.82 MB/s
         3 |          1 |       8192 |    0.028ms |    869.92 MB/s
         3 |          1 |      16384 |    0.032ms |   1519.81 MB/s
         3 |          1 |      32768 |    0.042ms |   2343.50 MB/s
         3 |          1 |      65536 |    0.058ms |   3387.49 MB/s
         3 |          1 |     131072 |    0.092ms |   4282.77 MB/s
         3 |          1 |     262144 |    0.207ms |   3805.10 MB/s
------------------------------------------------------------------
         3 |          2 |       4096 |    0.029ms |    424.99 MB/s
         3 |          2 |       8192 |    0.031ms |    784.19 MB/s
         3 |          2 |      16384 |    0.038ms |   1278.59 MB/s
         3 |          2 |      32768 |    0.051ms |   1943.59 MB/s
         3 |          2 |      65536 |    0.073ms |   2703.22 MB/s
         3 |          2 |     131072 |    0.159ms |   2476.07 MB/s
         3 |          2 |     262144 |    0.314ms |   2500.88 MB/s
------------------------------------------------------------------
         3 |          3 |       4096 |    0.034ms |    359.68 MB/s
         3 |          3 |       8192 |    0.036ms |    689.49 MB/s
         3 |          3 |      16384 |    0.046ms |   1079.24 MB/s
         3 |          3 |      32768 |    0.057ms |   1737.14 MB/s
         3 |          3 |      65536 |    0.111ms |   1777.88 MB/s
         3 |          3 |     131072 |    0.177ms |   2226.12 MB/s
         3 |          3 |     262144 |    0.319ms |   2463.98 MB/s
------------------------------------------------------------------
         3 |          4 |       4096 |    0.017ms |    733.80 MB/s
         3 |          4 |       8192 |    0.020ms |   1253.06 MB/s
         3 |          4 |      16384 |    0.032ms |   1549.42 MB/s
         3 |          4 |      32768 |    0.052ms |   1892.20 MB/s
         3 |          4 |      65536 |    0.087ms |   2258.76 MB/s
         3 |          4 |     131072 |    0.269ms |   1460.37 MB/s
         3 |          4 |     262144 |    0.580ms |   1354.75 MB/s
------------------------------------------------------------------
         4 |          1 |       4096 |    0.035ms |    465.53 MB/s
         4 |          1 |       8192 |    0.029ms |   1124.10 MB/s
         4 |          1 |      16384 |    0.063ms |   1038.60 MB/s
         4 |          1 |      32768 |    0.055ms |   2397.33 MB/s
         4 |          1 |      65536 |    0.112ms |   2338.08 MB/s
         4 |          1 |     131072 |    0.094ms |   5590.56 MB/s
         4 |          1 |     262144 |    0.155ms |   6746.66 MB/s
------------------------------------------------------------------
         4 |          2 |       4096 |    0.020ms |    814.12 MB/s
         4 |          2 |       8192 |    0.019ms |   1689.90 MB/s
         4 |          2 |      16384 |    0.048ms |   1359.91 MB/s
         4 |          2 |      32768 |    0.144ms |    913.01 MB/s
         4 |          2 |      65536 |    0.112ms |   2348.67 MB/s
         4 |          2 |     131072 |    0.201ms |   2604.60 MB/s
         4 |          2 |     262144 |    0.376ms |   2789.92 MB/s
------------------------------------------------------------------
         4 |          3 |       4096 |    0.048ms |    340.32 MB/s
         4 |          3 |       8192 |    0.050ms |    661.91 MB/s
         4 |          3 |      16384 |    0.067ms |    974.47 MB/s
         4 |          3 |      32768 |    0.098ms |   1341.55 MB/s
         4 |          3 |      65536 |    0.153ms |   1709.35 MB/s
         4 |          3 |     131072 |    0.332ms |   1577.18 MB/s
         4 |          3 |     262144 |    0.622ms |   1686.72 MB/s
------------------------------------------------------------------
         4 |          4 |       4096 |    0.054ms |    302.81 MB/s
         4 |          4 |       8192 |    0.066ms |    494.85 MB/s
         4 |          4 |      16384 |    0.086ms |    764.12 MB/s
         4 |          4 |      32768 |    0.115ms |   1135.61 MB/s
         4 |          4 |      65536 |    0.204ms |   1284.08 MB/s
         4 |          4 |     131072 |    0.418ms |   1254.68 MB/s
         4 |          4 |     262144 |    0.868ms |   1208.10 MB/s
------------------------------------------------------------------
         5 |          1 |       4096 |    0.031ms |    657.28 MB/s
         5 |          1 |       8192 |    0.031ms |   1332.81 MB/s
         5 |          1 |      16384 |    0.027ms |   3036.23 MB/s
         5 |          1 |      32768 |    0.035ms |   4670.84 MB/s
         5 |          1 |      65536 |    0.046ms |   7065.75 MB/s
         5 |          1 |     131072 |    0.090ms |   7291.80 MB/s
         5 |          1 |     262144 |    0.191ms |   6846.86 MB/s
------------------------------------------------------------------
         5 |          2 |       4096 |    0.016ms |   1305.83 MB/s
         5 |          2 |       8192 |    0.018ms |   2331.64 MB/s
         5 |          2 |      16384 |    0.023ms |   3533.83 MB/s
         5 |          2 |      32768 |    0.036ms |   4559.85 MB/s
         5 |          2 |      65536 |    0.088ms |   3728.74 MB/s
         5 |          2 |     131072 |    0.196ms |   3351.45 MB/s
         5 |          2 |     262144 |    0.500ms |   2622.55 MB/s
------------------------------------------------------------------
         5 |          3 |       4096 |    0.052ms |    393.15 MB/s
         5 |          3 |       8192 |    0.058ms |    711.33 MB/s
         5 |          3 |      16384 |    0.072ms |   1132.12 MB/s
         5 |          3 |      32768 |    0.106ms |   1549.38 MB/s
         5 |          3 |      65536 |    0.189ms |   1737.48 MB/s
         5 |          3 |     131072 |    0.438ms |   1495.94 MB/s
         5 |          3 |     262144 |    0.566ms |   2316.79 MB/s
------------------------------------------------------------------
         5 |          4 |       4096 |    0.026ms |    791.24 MB/s
         5 |          4 |       8192 |    0.026ms |   1554.12 MB/s
         5 |          4 |      16384 |    0.039ms |   2106.17 MB/s
         5 |          4 |      32768 |    0.068ms |   2421.31 MB/s
         5 |          4 |      65536 |    0.129ms |   2540.26 MB/s
         5 |          4 |     131072 |    0.326ms |   2011.25 MB/s
         5 |          4 |     262144 |    0.860ms |   1524.02 MB/s
------------------------------------------------------------------
         6 |          1 |       4096 |    0.052ms |    477.13 MB/s
         6 |          1 |       8192 |    0.045ms |   1086.18 MB/s
         6 |          1 |      16384 |    0.055ms |   1776.45 MB/s
         6 |          1 |      32768 |    0.058ms |   3366.84 MB/s
         6 |          1 |      65536 |    0.081ms |   4871.90 MB/s
         6 |          1 |     131072 |    0.146ms |   5388.97 MB/s
         6 |          1 |     262144 |    0.380ms |   4138.28 MB/s
------------------------------------------------------------------
         6 |          2 |       4096 |    0.053ms |    461.18 MB/s
         6 |          2 |       8192 |    0.040ms |   1241.51 MB/s
         6 |          2 |      16384 |    0.055ms |   1788.58 MB/s
         6 |          2 |      32768 |    0.084ms |   2350.93 MB/s
         6 |          2 |      65536 |    0.142ms |   2776.98 MB/s
         6 |          2 |     131072 |    0.330ms |   2384.01 MB/s
         6 |          2 |     262144 |    0.599ms |   2626.03 MB/s
------------------------------------------------------------------
         6 |          3 |       4096 |    0.045ms |    543.74 MB/s
         6 |          3 |       8192 |    0.051ms |    972.07 MB/s
         6 |          3 |      16384 |    0.073ms |   1351.82 MB/s
         6 |          3 |      32768 |    0.120ms |   1640.32 MB/s
         6 |          3 |      65536 |    0.219ms |   1793.42 MB/s
         6 |          3 |     131072 |    0.488ms |   1611.25 MB/s
         6 |          3 |     262144 |    1.081ms |   1454.59 MB/s
------------------------------------------------------------------
         6 |          4 |       4096 |    0.076ms |    324.81 MB/s
         6 |          4 |       8192 |    0.086ms |    573.26 MB/s
         6 |          4 |      16384 |    0.142ms |    693.51 MB/s
         6 |          4 |      32768 |    0.161ms |   1222.06 MB/s
         6 |          4 |      65536 |    0.307ms |   1282.11 MB/s
         6 |          4 |     131072 |    0.664ms |   1184.58 MB/s
         6 |          4 |     262144 |    1.038ms |   1515.57 MB/s
------------------------------------------------------------------
         7 |          1 |       4096 |    0.025ms |   1126.51 MB/s
         7 |          1 |       8192 |    0.024ms |   2413.93 MB/s
         7 |          1 |      16384 |    0.028ms |   4124.71 MB/s
         7 |          1 |      32768 |    0.040ms |   5686.78 MB/s
         7 |          1 |      65536 |    0.077ms |   5925.27 MB/s
         7 |          1 |     131072 |    0.136ms |   6747.68 MB/s
         7 |          1 |     262144 |    0.265ms |   6913.99 MB/s
------------------------------------------------------------------
         7 |          2 |       4096 |    0.028ms |   1023.36 MB/s
         7 |          2 |       8192 |    0.031ms |   1871.57 MB/s
         7 |          2 |      16384 |    0.047ms |   2462.79 MB/s
         7 |          2 |      32768 |    0.075ms |   3078.03 MB/s
         7 |          2 |      65536 |    0.144ms |   3190.76 MB/s
         7 |          2 |     131072 |    0.309ms |   2971.00 MB/s
         7 |          2 |     262144 |    0.724ms |   2533.48 MB/s
------------------------------------------------------------------
         7 |          3 |       4096 |    0.042ms |    680.79 MB/s
         7 |          3 |       8192 |    0.032ms |   1807.93 MB/s
         7 |          3 |      16384 |    0.046ms |   2495.59 MB/s
         7 |          3 |      32768 |    0.084ms |   2731.94 MB/s
         7 |          3 |      65536 |    0.143ms |   3213.37 MB/s
         7 |          3 |     131072 |    0.316ms |   2905.82 MB/s
         7 |          3 |     262144 |    0.678ms |   2708.27 MB/s
------------------------------------------------------------------
         7 |          4 |       4096 |    0.027ms |   1081.68 MB/s
         7 |          4 |       8192 |    0.032ms |   1813.53 MB/s
         7 |          4 |      16384 |    0.050ms |   2275.95 MB/s
         7 |          4 |      32768 |    0.089ms |   2573.07 MB/s
         7 |          4 |      65536 |    0.203ms |   2254.50 MB/s
         7 |          4 |     131072 |    0.597ms |   1536.29 MB/s
         7 |          4 |     262144 |    1.528ms |   1201.01 MB/s
------------------------------------------------------------------
         8 |          1 |       4096 |    0.027ms |   1219.83 MB/s
         8 |          1 |       8192 |    0.019ms |   3510.67 MB/s
         8 |          1 |      16384 |    0.026ms |   5043.17 MB/s
         8 |          1 |      32768 |    0.045ms |   5820.19 MB/s
         8 |          1 |      65536 |    0.077ms |   6821.77 MB/s
         8 |          1 |     131072 |    0.147ms |   7126.81 MB/s
         8 |          1 |     262144 |    0.314ms |   6679.59 MB/s
------------------------------------------------------------------
         8 |          2 |       4096 |    0.024ms |   1346.31 MB/s
         8 |          2 |       8192 |    0.026ms |   2519.58 MB/s
         8 |          2 |      16384 |    0.035ms |   3703.69 MB/s
         8 |          2 |      32768 |    0.071ms |   3687.32 MB/s
         8 |          2 |      65536 |    0.199ms |   2637.10 MB/s
         8 |          2 |     131072 |    0.358ms |   2932.52 MB/s
         8 |          2 |     262144 |    0.716ms |   2930.54 MB/s
------------------------------------------------------------------
         8 |          3 |       4096 |    0.055ms |    600.97 MB/s
         8 |          3 |       8192 |    0.064ms |   1025.95 MB/s
         8 |          3 |      16384 |    0.092ms |   1427.07 MB/s
         8 |          3 |      32768 |    0.108ms |   2434.88 MB/s
         8 |          3 |      65536 |    0.178ms |   2946.99 MB/s
         8 |          3 |     131072 |    0.375ms |   2795.62 MB/s
         8 |          3 |     262144 |    1.058ms |   1981.65 MB/s
------------------------------------------------------------------
         8 |          4 |       4096 |    0.076ms |    429.30 MB/s
         8 |          4 |       8192 |    0.057ms |   1147.05 MB/s
         8 |          4 |      16384 |    0.065ms |   2017.41 MB/s
         8 |          4 |      32768 |    0.136ms |   1931.71 MB/s
         8 |          4 |      65536 |    0.419ms |   1250.56 MB/s
         8 |          4 |     131072 |    0.667ms |   1571.62 MB/s
         8 |          4 |     262144 |    1.469ms |   1427.40 MB/s
------------------------------------------------------------------
         9 |          1 |       4096 |    0.019ms |   1942.36 MB/s
         9 |          1 |       8192 |    0.019ms |   3873.97 MB/s
         9 |          1 |      16384 |    0.027ms |   5505.82 MB/s
         9 |          1 |      32768 |    0.049ms |   6054.89 MB/s
         9 |          1 |      65536 |    0.120ms |   4900.54 MB/s
         9 |          1 |     131072 |    0.241ms |   4888.84 MB/s
         9 |          1 |     262144 |    0.485ms |   4862.01 MB/s
------------------------------------------------------------------
         9 |          2 |       4096 |    0.026ms |   1445.32 MB/s
         9 |          2 |       8192 |    0.026ms |   2881.95 MB/s
         9 |          2 |      16384 |    0.061ms |   2418.11 MB/s
         9 |          2 |      32768 |    0.070ms |   4204.51 MB/s
         9 |          2 |      65536 |    0.146ms |   4040.35 MB/s
         9 |          2 |     131072 |    0.424ms |   2778.94 MB/s
         9 |          2 |     262144 |    0.744ms |   3172.73 MB/s
------------------------------------------------------------------
         9 |          3 |       4096 |    0.043ms |    864.34 MB/s
         9 |          3 |       8192 |    0.079ms |    933.42 MB/s
         9 |          3 |      16384 |    0.108ms |   1361.89 MB/s
         9 |          3 |      32768 |    0.176ms |   1673.63 MB/s
         9 |          3 |      65536 |    0.357ms |   1654.12 MB/s
         9 |          3 |     131072 |    0.688ms |   1713.51 MB/s
         9 |          3 |     262144 |    0.876ms |   2692.89 MB/s
------------------------------------------------------------------
         9 |          4 |       4096 |    0.042ms |    874.82 MB/s
         9 |          4 |       8192 |    0.042ms |   1763.38 MB/s
         9 |          4 |      16384 |    0.068ms |   2169.67 MB/s
         9 |          4 |      32768 |    0.128ms |   2312.61 MB/s
         9 |          4 |      65536 |    0.271ms |   2176.90 MB/s
         9 |          4 |     131072 |    0.527ms |   2237.87 MB/s
         9 |          4 |     262144 |    1.118ms |   2109.73 MB/s
------------------------------------------------------------------
        10 |          1 |       4096 |    0.036ms |   1123.33 MB/s
        10 |          1 |       8192 |    0.020ms |   4014.80 MB/s
        10 |          1 |      16384 |    0.028ms |   5803.76 MB/s
        10 |          1 |      32768 |    0.048ms |   6847.65 MB/s
        10 |          1 |      65536 |    0.103ms |   6369.64 MB/s
        10 |          1 |     131072 |    0.203ms |   6449.50 MB/s
        10 |          1 |     262144 |    0.381ms |   6877.92 MB/s
------------------------------------------------------------------
        10 |          2 |       4096 |    0.025ms |   1615.31 MB/s
        10 |          2 |       8192 |    0.027ms |   3005.63 MB/s
        10 |          2 |      16384 |    0.042ms |   3896.50 MB/s
        10 |          2 |      32768 |    0.077ms |   4242.03 MB/s
        10 |          2 |      65536 |    0.158ms |   4160.09 MB/s
        10 |          2 |     131072 |    0.337ms |   3891.55 MB/s
        10 |          2 |     262144 |    0.898ms |   2918.96 MB/s
------------------------------------------------------------------
        10 |          3 |       4096 |    0.075ms |    546.04 MB/s
        10 |          3 |       8192 |    0.075ms |   1087.65 MB/s
        10 |          3 |      16384 |    0.110ms |   1488.85 MB/s
        10 |          3 |      32768 |    0.221ms |   1483.70 MB/s
        10 |          3 |      65536 |    0.384ms |   1705.07 MB/s
        10 |          3 |     131072 |    0.727ms |   1801.73 MB/s
        10 |          3 |     262144 |    1.322ms |   1982.67 MB/s
------------------------------------------------------------------
        10 |          4 |       4096 |    0.041ms |   1000.43 MB/s
        10 |          4 |       8192 |    0.050ms |   1630.48 MB/s
        10 |          4 |      16384 |    0.078ms |   2087.18 MB/s
        10 |          4 |      32768 |    0.144ms |   2280.40 MB/s
        10 |          4 |      65536 |    0.296ms |   2213.96 MB/s
        10 |          4 |     131072 |    0.605ms |   2166.76 MB/s
        10 |          4 |     262144 |    1.788ms |   1466.22 MB/s
------------------------------------------------------------------
        11 |          1 |       4096 |    0.045ms |   1010.38 MB/s
        11 |          1 |       8192 |    0.043ms |   2075.58 MB/s
        11 |          1 |      16384 |    0.060ms |   3023.78 MB/s
        11 |          1 |      32768 |    0.093ms |   3881.32 MB/s
        11 |          1 |      65536 |    0.137ms |   5255.88 MB/s
        11 |          1 |     131072 |    0.272ms |   5304.03 MB/s
        11 |          1 |     262144 |    0.606ms |   4754.90 MB/s
------------------------------------------------------------------
        11 |          2 |       4096 |    0.057ms |    795.16 MB/s
        11 |          2 |       8192 |    0.080ms |   1123.24 MB/s
        11 |          2 |      16384 |    0.106ms |   1699.75 MB/s
        11 |          2 |      32768 |    0.158ms |   2275.31 MB/s
        11 |          2 |      65536 |    0.280ms |   2574.74 MB/s
        11 |          2 |     131072 |    0.526ms |   2740.81 MB/s
        11 |          2 |     262144 |    1.020ms |   2827.50 MB/s
------------------------------------------------------------------
        11 |          3 |       4096 |    0.091ms |    492.48 MB/s
        11 |          3 |       8192 |    0.099ms |    908.49 MB/s
        11 |          3 |      16384 |    0.139ms |   1298.14 MB/s
        11 |          3 |      32768 |    0.235ms |   1536.05 MB/s
        11 |          3 |      65536 |    0.409ms |   1762.22 MB/s
        11 |          3 |     131072 |    0.794ms |   1815.97 MB/s
        11 |          3 |     262144 |    1.468ms |   1964.00 MB/s
------------------------------------------------------------------
        11 |          4 |       4096 |    0.101ms |    444.69 MB/s
        11 |          4 |       8192 |    0.110ms |    818.81 MB/s
        11 |          4 |      16384 |    0.168ms |   1071.35 MB/s
        11 |          4 |      32768 |    0.301ms |   1199.00 MB/s
        11 |          4 |      65536 |    0.453ms |   1592.52 MB/s
        11 |          4 |     131072 |    0.785ms |   1836.52 MB/s
        11 |          4 |     262144 |    1.545ms |   1866.93 MB/s
------------------------------------------------------------------
        12 |          1 |       4096 |    0.033ms |   1506.80 MB/s
        12 |          1 |       8192 |    0.026ms |   3846.75 MB/s
        12 |          1 |      16384 |    0.031ms |   6296.75 MB/s
        12 |          1 |      32768 |    0.056ms |   7024.92 MB/s
        12 |          1 |      65536 |    0.116ms |   6766.89 MB/s
        12 |          1 |     131072 |    0.297ms |   5288.24 MB/s
        12 |          1 |     262144 |    0.604ms |   5209.57 MB/s
------------------------------------------------------------------
        12 |          2 |       4096 |    0.042ms |   1180.76 MB/s
        12 |          2 |       8192 |    0.031ms |   3217.53 MB/s
        12 |          2 |      16384 |    0.047ms |   4224.97 MB/s
        12 |          2 |      32768 |    0.086ms |   4553.87 MB/s
        12 |          2 |      65536 |    0.231ms |   3403.55 MB/s
        12 |          2 |     131072 |    0.396ms |   3974.81 MB/s
        12 |          2 |     262144 |    0.818ms |   3846.30 MB/s
------------------------------------------------------------------
        12 |          3 |       4096 |    0.077ms |    641.73 MB/s
        12 |          3 |       8192 |    0.047ms |   2087.45 MB/s
        12 |          3 |      16384 |    0.071ms |   2783.82 MB/s
        12 |          3 |      32768 |    0.156ms |   2518.63 MB/s
        12 |          3 |      65536 |    0.391ms |   2011.15 MB/s
        12 |          3 |     131072 |    0.831ms |   1893.50 MB/s
        12 |          3 |     262144 |    1.836ms |   1713.08 MB/s
------------------------------------------------------------------
        12 |          4 |       4096 |    0.105ms |    468.09 MB/s
        12 |          4 |       8192 |    0.124ms |    789.83 MB/s
        12 |          4 |      16384 |    0.209ms |    939.05 MB/s
        12 |          4 |      32768 |    0.361ms |   1090.27 MB/s
        12 |          4 |      65536 |    0.603ms |   1305.18 MB/s
        12 |          4 |     131072 |    0.665ms |   2366.04 MB/s
        12 |          4 |     262144 |    1.392ms |   2259.23 MB/s
------------------------------------------------------------------
        13 |          1 |       4096 |    0.025ms |   2134.14 MB/s
        13 |          1 |       8192 |    0.028ms |   3868.40 MB/s
        13 |          1 |      16384 |    0.038ms |   5540.46 MB/s
        13 |          1 |      32768 |    0.064ms |   6622.42 MB/s
        13 |          1 |      65536 |    0.116ms |   7335.75 MB/s
        13 |          1 |     131072 |    0.222ms |   7660.11 MB/s
        13 |          1 |     262144 |    0.433ms |   7867.25 MB/s
------------------------------------------------------------------
        13 |          2 |       4096 |    0.044ms |   1200.09 MB/s
        13 |          2 |       8192 |    0.078ms |   1358.15 MB/s
        13 |          2 |      16384 |    0.104ms |   2041.43 MB/s
        13 |          2 |      32768 |    0.114ms |   3744.41 MB/s
        13 |          2 |      65536 |    0.215ms |   3957.22 MB/s
        13 |          2 |     131072 |    0.561ms |   3037.70 MB/s
        13 |          2 |     262144 |    1.182ms |   2882.19 MB/s
------------------------------------------------------------------
        13 |          3 |       4096 |    0.044ms |   1209.99 MB/s
        13 |          3 |       8192 |    0.056ms |   1917.20 MB/s
        13 |          3 |      16384 |    0.083ms |   2558.44 MB/s
        13 |          3 |      32768 |    0.153ms |   2787.19 MB/s
        13 |          3 |      65536 |    0.382ms |   2232.32 MB/s
        13 |          3 |     131072 |    0.959ms |   1776.97 MB/s
        13 |          3 |     262144 |    1.288ms |   2645.11 MB/s
------------------------------------------------------------------
        13 |          4 |       4096 |    0.116ms |    458.10 MB/s
        13 |          4 |       8192 |    0.136ms |    785.46 MB/s
        13 |          4 |      16384 |    0.272ms |    783.68 MB/s
        13 |          4 |      32768 |    0.482ms |    884.61 MB/s
        13 |          4 |      65536 |    0.826ms |   1031.92 MB/s
        13 |          4 |     131072 |    1.269ms |   1343.11 MB/s
        13 |          4 |     262144 |    2.995ms |   1137.93 MB/s
------------------------------------------------------------------
        14 |          1 |       4096 |    0.061ms |    942.09 MB/s
        14 |          1 |       8192 |    0.029ms |   3992.90 MB/s
        14 |          1 |      16384 |    0.038ms |   6011.98 MB/s
        14 |          1 |      32768 |    0.074ms |   6227.11 MB/s
        14 |          1 |      65536 |    0.180ms |   5107.08 MB/s
        14 |          1 |     131072 |    0.285ms |   6434.62 MB/s
        14 |          1 |     262144 |    0.678ms |   5415.01 MB/s
------------------------------------------------------------------
        14 |          2 |       4096 |    0.062ms |    918.43 MB/s
        14 |          2 |       8192 |    0.036ms |   3224.61 MB/s
        14 |          2 |      16384 |    0.055ms |   4195.08 MB/s
        14 |          2 |      32768 |    0.124ms |   3704.85 MB/s
        14 |          2 |      65536 |    0.255ms |   3600.49 MB/s
        14 |          2 |     131072 |    0.668ms |   2747.86 MB/s
        14 |          2 |     262144 |    1.189ms |   3086.86 MB/s
------------------------------------------------------------------
        14 |          3 |       4096 |    0.151ms |    378.75 MB/s
        14 |          3 |       8192 |    0.161ms |    710.66 MB/s
        14 |          3 |      16384 |    0.187ms |   1225.34 MB/s
        14 |          3 |      32768 |    0.284ms |   1612.96 MB/s
        14 |          3 |      65536 |    0.435ms |   2108.42 MB/s
        14 |          3 |     131072 |    0.825ms |   2224.69 MB/s
        14 |          3 |     262144 |    2.075ms |   1768.62 MB/s
------------------------------------------------------------------
        14 |          4 |       4096 |    0.096ms |    599.04 MB/s
        14 |          4 |       8192 |    0.124ms |    922.79 MB/s
        14 |          4 |      16384 |    0.173ms |   1328.86 MB/s
        14 |          4 |      32768 |    0.361ms |   1271.49 MB/s
        14 |          4 |      65536 |    0.775ms |   1184.08 MB/s
        14 |          4 |     131072 |    1.733ms |   1059.02 MB/s
        14 |          4 |     262144 |    3.206ms |   1144.88 MB/s
------------------------------------------------------------------
        15 |          1 |       4096 |    0.041ms |   1488.70 MB/s
        15 |          1 |       8192 |    0.023ms |   5249.57 MB/s
        15 |          1 |      16384 |    0.036ms |   6831.32 MB/s
        15 |          1 |      32768 |    0.084ms |   5847.66 MB/s
        15 |          1 |      65536 |    0.180ms |   5476.34 MB/s
        15 |          1 |     131072 |    0.371ms |   5292.93 MB/s
        15 |          1 |     262144 |    0.805ms |   4886.71 MB/s
------------------------------------------------------------------
        15 |          2 |       4096 |    0.074ms |    833.18 MB/s
        15 |          2 |       8192 |    0.087ms |   1409.39 MB/s
        15 |          2 |      16384 |    0.124ms |   1987.76 MB/s
        15 |          2 |      32768 |    0.208ms |   2362.27 MB/s
        15 |          2 |      65536 |    0.386ms |   2544.60 MB/s
        15 |          2 |     131072 |    0.528ms |   3725.84 MB/s
        15 |          2 |     262144 |    1.383ms |   2843.23 MB/s
------------------------------------------------------------------
        15 |          3 |       4096 |    0.153ms |    400.32 MB/s
        15 |          3 |       8192 |    0.172ms |    715.30 MB/s
        15 |          3 |      16384 |    0.274ms |    898.09 MB/s
        15 |          3 |      32768 |    0.343ms |   1433.84 MB/s
        15 |          3 |      65536 |    0.436ms |   2256.32 MB/s
        15 |          3 |     131072 |    1.305ms |   1507.09 MB/s
        15 |          3 |     262144 |    2.711ms |   1450.67 MB/s
------------------------------------------------------------------
        15 |          4 |       4096 |    0.203ms |    302.53 MB/s
        15 |          4 |       8192 |    0.241ms |    510.74 MB/s
        15 |          4 |      16384 |    0.360ms |    683.29 MB/s
        15 |          4 |      32768 |    0.546ms |    900.71 MB/s
        15 |          4 |      65536 |    0.780ms |   1260.95 MB/s
        15 |          4 |     131072 |    1.500ms |   1311.12 MB/s
        15 |          4 |     262144 |    3.865ms |   1017.44 MB/s
------------------------------------------------------------------
        16 |          1 |       4096 |    0.042ms |   1552.73 MB/s
        16 |          1 |       8192 |    0.032ms |   4121.66 MB/s
        16 |          1 |      16384 |    0.042ms |   6285.35 MB/s
        16 |          1 |      32768 |    0.077ms |   6833.44 MB/s
        16 |          1 |      65536 |    0.145ms |   7242.04 MB/s
        16 |          1 |     131072 |    0.279ms |   7517.19 MB/s
        16 |          1 |     262144 |    0.651ms |   6442.87 MB/s
------------------------------------------------------------------
        16 |          2 |       4096 |    0.104ms |    631.30 MB/s
        16 |          2 |       8192 |    0.099ms |   1318.02 MB/s
        16 |          2 |      16384 |    0.136ms |   1934.52 MB/s
        16 |          2 |      32768 |    0.244ms |   2150.05 MB/s
        16 |          2 |      65536 |    0.459ms |   2283.66 MB/s
        16 |          2 |     131072 |    0.549ms |   3822.94 MB/s
        16 |          2 |     262144 |    1.513ms |   2771.55 MB/s
------------------------------------------------------------------
        16 |          3 |       4096 |    0.097ms |    673.77 MB/s
        16 |          3 |       8192 |    0.164ms |    800.50 MB/s
        16 |          3 |      16384 |    0.287ms |    911.98 MB/s
        16 |          3 |      32768 |    0.394ms |   1332.26 MB/s
        16 |          3 |      65536 |    0.862ms |   1216.30 MB/s
        16 |          3 |     131072 |    1.497ms |   1401.13 MB/s
        16 |          3 |     262144 |    2.610ms |   1606.73 MB/s
------------------------------------------------------------------
        16 |          4 |       4096 |    0.196ms |    334.94 MB/s
        16 |          4 |       8192 |    0.272ms |    481.51 MB/s
        16 |          4 |      16384 |    0.414ms |    633.72 MB/s
        16 |          4 |      32768 |    0.687ms |    763.58 MB/s
        16 |          4 |      65536 |    1.320ms |    794.35 MB/s
        16 |          4 |     131072 |    2.455ms |    854.20 MB/s
        16 |          4 |     262144 |    4.159ms |   1008.44 MB/s
------------------------------------------------------------------
        17 |          1 |       4096 |    0.039ms |   1786.53 MB/s
        17 |          1 |       8192 |    0.032ms |   4406.90 MB/s
        17 |          1 |      16384 |    0.039ms |   7198.52 MB/s
        17 |          1 |      32768 |    0.089ms |   6225.07 MB/s
        17 |          1 |      65536 |    0.195ms |   5723.37 MB/s
        17 |          1 |     131072 |    0.397ms |   5615.61 MB/s
        17 |          1 |     262144 |    0.927ms |   4807.80 MB/s
------------------------------------------------------------------
        17 |          2 |       4096 |    0.095ms |    732.18 MB/s
        17 |          2 |       8192 |    0.120ms |   1160.86 MB/s
        17 |          2 |      16384 |    0.167ms |   1669.11 MB/s
        17 |          2 |      32768 |    0.197ms |   2823.38 MB/s
        17 |          2 |      65536 |    0.484ms |   2300.66 MB/s
        17 |          2 |     131072 |    0.909ms |   2450.82 MB/s
        17 |          2 |     262144 |    1.808ms |   2464.89 MB/s
------------------------------------------------------------------
        17 |          3 |       4096 |    0.174ms |    400.13 MB/s
        17 |          3 |       8192 |    0.160ms |    869.95 MB/s
        17 |          3 |      16384 |    0.169ms |   1650.31 MB/s
        17 |          3 |      32768 |    0.343ms |   1621.96 MB/s
        17 |          3 |      65536 |    1.011ms |   1102.15 MB/s
        17 |          3 |     131072 |    1.571ms |   1418.49 MB/s
        17 |          3 |     262144 |    3.603ms |   1236.88 MB/s
------------------------------------------------------------------
        17 |          4 |       4096 |    0.163ms |    426.60 MB/s
        17 |          4 |       8192 |    0.268ms |    519.08 MB/s
        17 |          4 |      16384 |    0.452ms |    616.28 MB/s
        17 |          4 |      32768 |    0.665ms |    837.55 MB/s
        17 |          4 |      65536 |    1.318ms |    845.58 MB/s
        17 |          4 |     131072 |    2.177ms |   1023.76 MB/s
        17 |          4 |     262144 |    3.081ms |   1446.64 MB/s
------------------------------------------------------------------
        18 |          1 |       4096 |    0.035ms |   2112.68 MB/s
        18 |          1 |       8192 |    0.026ms |   5642.77 MB/s
        18 |          1 |      16384 |    0.038ms |   7750.57 MB/s
        18 |          1 |      32768 |    0.074ms |   7921.27 MB/s
        18 |          1 |      65536 |    0.143ms |   8244.15 MB/s
        18 |          1 |     131072 |    0.276ms |   8557.26 MB/s
        18 |          1 |     262144 |    0.861ms |   5477.26 MB/s
------------------------------------------------------------------
        18 |          2 |       4096 |    0.104ms |    710.93 MB/s
        18 |          2 |       8192 |    0.115ms |   1283.10 MB/s
        18 |          2 |      16384 |    0.149ms |   1983.77 MB/s
        18 |          2 |      32768 |    0.257ms |   2295.50 MB/s
        18 |          2 |      65536 |    0.485ms |   2432.36 MB/s
        18 |          2 |     131072 |    0.948ms |   2489.86 MB/s
        18 |          2 |     262144 |    1.606ms |   2938.36 MB/s
------------------------------------------------------------------
        18 |          3 |       4096 |    0.189ms |    389.93 MB/s
        18 |          3 |       8192 |    0.235ms |    627.28 MB/s
        18 |          3 |      16384 |    0.333ms |    885.56 MB/s
        18 |          3 |      32768 |    0.351ms |   1679.48 MB/s
        18 |          3 |      65536 |    0.836ms |   1411.58 MB/s
        18 |          3 |     131072 |    1.807ms |   1305.74 MB/s
        18 |          3 |     262144 |    3.279ms |   1439.22 MB/s
------------------------------------------------------------------
        18 |          4 |       4096 |    0.217ms |    339.90 MB/s
        18 |          4 |       8192 |    0.241ms |    611.82 MB/s
        18 |          4 |      16384 |    0.335ms |    881.27 MB/s
        18 |          4 |      32768 |    0.640ms |    921.85 MB/s
        18 |          4 |      65536 |    0.843ms |   1400.02 MB/s
        18 |          4 |     131072 |    1.560ms |   1511.92 MB/s
        18 |          4 |     262144 |    3.821ms |   1234.81 MB/s
------------------------------------------------------------------
        19 |          1 |       4096 |    0.054ms |   1437.76 MB/s
        19 |          1 |       8192 |    0.052ms |   2969.23 MB/s
        19 |          1 |      16384 |    0.072ms |   4297.80 MB/s
        19 |          1 |      32768 |    0.128ms |   4846.39 MB/s
        19 |          1 |      65536 |    0.230ms |   5404.29 MB/s
        19 |          1 |     131072 |    0.454ms |   5490.88 MB/s
        19 |          1 |     262144 |    1.025ms |   4859.20 MB/s
------------------------------------------------------------------
        19 |          2 |       4096 |    0.059ms |   1320.96 MB/s
        19 |          2 |       8192 |    0.067ms |   2315.47 MB/s
        19 |          2 |      16384 |    0.104ms |   2999.96 MB/s
        19 |          2 |      32768 |    0.176ms |   3530.09 MB/s
        19 |          2 |      65536 |    0.336ms |   3701.82 MB/s
        19 |          2 |     131072 |    0.828ms |   3006.42 MB/s
        19 |          2 |     262144 |    2.024ms |   2460.29 MB/s
------------------------------------------------------------------
        19 |          3 |       4096 |    0.149ms |    520.78 MB/s
        19 |          3 |       8192 |    0.258ms |    603.14 MB/s
        19 |          3 |      16384 |    0.356ms |    875.40 MB/s
        19 |          3 |      32768 |    0.537ms |   1160.44 MB/s
        19 |          3 |      65536 |    0.850ms |   1464.44 MB/s
        19 |          3 |     131072 |    2.024ms |   1230.22 MB/s
        19 |          3 |     262144 |    4.106ms |   1212.98 MB/s
------------------------------------------------------------------
        19 |          4 |       4096 |    0.226ms |    344.37 MB/s
        19 |          4 |       8192 |    0.335ms |    465.10 MB/s
        19 |          4 |      16384 |    0.478ms |    651.67 MB/s
        19 |          4 |      32768 |    0.606ms |   1028.16 MB/s
        19 |          4 |      65536 |    1.451ms |    858.42 MB/s
        19 |          4 |     131072 |    1.898ms |   1312.18 MB/s
        19 |          4 |     262144 |    3.311ms |   1504.34 MB/s
------------------------------------------------------------------
        20 |          1 |       4096 |    0.037ms |   2235.86 MB/s
        20 |          1 |       8192 |    0.029ms |   5680.54 MB/s
        20 |          1 |      16384 |    0.042ms |   7815.00 MB/s
        20 |          1 |      32768 |    0.083ms |   7922.18 MB/s
        20 |          1 |      65536 |    0.171ms |   7661.03 MB/s
        20 |          1 |     131072 |    0.340ms |   7702.11 MB/s
        20 |          1 |     262144 |    0.646ms |   8116.93 MB/s
------------------------------------------------------------------
        20 |          2 |       4096 |    0.056ms |   1466.84 MB/s
        20 |          2 |       8192 |    0.073ms |   2236.09 MB/s
        20 |          2 |      16384 |    0.090ms |   3649.78 MB/s
        20 |          2 |      32768 |    0.192ms |   3406.91 MB/s
        20 |          2 |      65536 |    0.371ms |   3536.40 MB/s
        20 |          2 |     131072 |    0.652ms |   4022.86 MB/s
        20 |          2 |     262144 |    1.447ms |   3623.86 MB/s
------------------------------------------------------------------
        20 |          3 |       4096 |    0.097ms |    843.67 MB/s
        20 |          3 |       8192 |    0.113ms |   1456.28 MB/s
        20 |          3 |      16384 |    0.177ms |   1855.48 MB/s
        20 |          3 |      32768 |    0.310ms |   2114.10 MB/s
        20 |          3 |      65536 |    0.627ms |   2092.02 MB/s
        20 |          3 |     131072 |    1.245ms |   2105.94 MB/s
        20 |          3 |     262144 |    2.579ms |   2032.83 MB/s
------------------------------------------------------------------
        20 |          4 |       4096 |    0.121ms |    679.09 MB/s
        20 |          4 |       8192 |    0.152ms |   1077.19 MB/s
        20 |          4 |      16384 |    0.245ms |   1335.49 MB/s
        20 |          4 |      32768 |    0.418ms |   1568.58 MB/s
        20 |          4 |      65536 |    0.836ms |   1567.14 MB/s
        20 |          4 |     131072 |    1.702ms |   1540.08 MB/s
        20 |          4 |     262144 |    4.535ms |   1156.01 MB/s
------------------------------------------------------------------

Usage

Adjust threadpool size and control concurrency

Please see the crypto-async module for advice on adjusting threadpool size and controlling concurrency.

Encoding Parity Shards

var ReedSolomon = require('@ronomon/reed-solomon');

// Specify the number of data shards (<= ReedSolomon.MAX_K):
var k = 6;

// Specify the number of parity shards (<= ReedSolomon.MAX_M):
var m = 3; // Protect against the loss of any 3 data or parity shards.

// Create an encoding context (can be cached and re-used concurrently):
var context = ReedSolomon.create(k, m);

// Specify the size of each shard in bytes (must be a multiple of 8 bytes):
var shardSize = 65536;

// Allocate the data buffer containing all data shards:
var buffer = Buffer.alloc(shardSize * k);

// Specify the offset into the data buffer at which data shards begin:
// This allows you to include a header.
var bufferOffset = 0;

// Specify the size after this offset of all data shards:
// This allows you to include a footer.
var bufferSize = shardSize * k;

// Allocate the parity buffer containing all parity shards:
var parity = Buffer.alloc(shardSize * m);

// Specify the offset into the parity buffer at which parity shards begin:
// This allows you to include a header.
var parityOffset = 0;

// Specify the size after this offset of all parity shards:
// This allows you to include a footer.
var paritySize = shardSize * m;

// Specify the sources, present in buffer or parity (as bit flags):
// We are encoding parity shards, so we mark all data shards as sources.
var sources = 0;
for (var i = 0; i < k; i++) sources |= (1 << i);

// Specify the targets, missing in buffer or parity, which should be encoded:
// We are encoding parity shards, so we mark all parity shards as targets:
var targets = 0;
for (var i = k; i < k + m; i++) targets |= (1 << i);

// Encode all parity shards:
ReedSolomon.encode(
  context,
  sources,
  targets,
  buffer,
  bufferOffset,
  bufferSize,
  parity,
  parityOffset,
  paritySize,
  function(error) {
    if (error) throw error;
    // Parity shards now contain parity data.
  }
);

Encoding Corrupted Shards

// Corrupt first data shard:
buffer[bufferOffset + (shardSize * 0)] = 255;

// Corrupt first parity shard:
parity[parityOffset + (shardSize * 0)] = 255;

// We still have enough parity to corrupt one more shard.

// Specify the targets, missing in buffer or parity, which should be encoded:
var targets = 0;
targets |= (1 << 0); // Data shard at index 0 needs to be encoded.
targets |= (1 << k); // Parity shard at index 6 (k + 0) needs to be encoded.

// Specify the sources, present in buffer or parity:
// We need at least k sources.
// For this example, we assume that a shard is a source if it is not a target.
// An optimization is available here:
// If a shard is not a source or target, it might not be encoded.
// The shard may be encoded if needed to encode other shards, but otherwise not.
var sources = 0;
for (var i = 0; i < k + m; i++) {
  if (targets & (1 << i)) continue;
  sources |= (1 << i);
}

// Encode the corrupted data and parity shards:
ReedSolomon.encode(
  context,
  sources,
  targets,
  buffer,
  bufferOffset,
  bufferSize,
  parity,
  parityOffset,
  paritySize,
  function(error) {
    if (error) throw error;
    // Data shard at index 0 has been repaired.
    // Parity shard at index 6 has been repaired.
  }
);

Tests

reed-solomon ships with extensive tests, including a long-running fuzz test.

node test.js

Benchmark

node benchmark.js