update
This commit is contained in:
parent
d9becc67b6
commit
9308795b8b
964 changed files with 104265 additions and 16 deletions
21
node_modules/flatstr/LICENSE
generated
vendored
Normal file
21
node_modules/flatstr/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 David Mark Clements
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
234
node_modules/flatstr/alt-benchmark.js
generated
vendored
Normal file
234
node_modules/flatstr/alt-benchmark.js
generated
vendored
Normal file
|
@ -0,0 +1,234 @@
|
|||
'use strict'
|
||||
var nul = process.platform === 'win32' ? '\\\\.\\NUL' : '/dev/null'
|
||||
var bench = require('fastbench')
|
||||
var stream = require('fs').createWriteStream(nul)
|
||||
var alt0 = require('./')
|
||||
var largeStr = JSON.stringify(require('./package.json'))
|
||||
largeStr += largeStr
|
||||
largeStr += largeStr
|
||||
|
||||
var run = bench([
|
||||
function alt0ManySmallConcats (cb) {
|
||||
stream.write(alt0(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt1ManySmallConcats (cb) {
|
||||
stream.write(alt1(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt2ManySmallConcats (cb) {
|
||||
stream.write(alt2(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt3ManySmallConcats (cb) {
|
||||
stream.write(alt3(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt4ManySmallConcats (cb) {
|
||||
stream.write(alt4(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt5ManySmallConcats (cb) {
|
||||
stream.write(alt5(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt6ManySmallConcats (cb) {
|
||||
stream.write(alt6(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt7ManySmallConcats (cb) {
|
||||
stream.write(alt7(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt8ManySmallConcats (cb) {
|
||||
stream.write(alt8(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt9ManySmallConcats (cb) {
|
||||
stream.write(alt9(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt0SeveralLargeConcats (cb) {
|
||||
stream.write(alt0(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt1SeveralLargeConcats (cb) {
|
||||
stream.write(alt1(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt2SeveralLargeConcats (cb) {
|
||||
stream.write(alt2(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt3SeveralLargeConcats (cb) {
|
||||
stream.write(alt3(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt4SeveralLargeConcats (cb) {
|
||||
stream.write(alt4(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt5SeveralLargeConcats (cb) {
|
||||
stream.write(alt5(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt6SeveralLargeConcats (cb) {
|
||||
stream.write(alt6(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt7SeveralLargeConcats (cb) {
|
||||
stream.write(alt7(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt8SeveralLargeConcats (cb) {
|
||||
stream.write(alt8(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt9SeveralLargeConcats (cb) {
|
||||
stream.write(alt9(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt0ExponentialSmallConcats (cb) {
|
||||
stream.write(alt0(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt1ExponentialSmallConcats (cb) {
|
||||
stream.write(alt1(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt2ExponentialSmallConcats (cb) {
|
||||
stream.write(alt2(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt3ExponentialSmallConcats (cb) {
|
||||
stream.write(alt3(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt4ExponentialSmallConcats (cb) {
|
||||
stream.write(alt4(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt5ExponentialSmallConcats (cb) {
|
||||
stream.write(alt5(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt6ExponentialSmallConcats (cb) {
|
||||
stream.write(alt6(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt7ExponentialSmallConcats (cb) {
|
||||
stream.write(alt7(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt8ExponentialSmallConcats (cb) {
|
||||
stream.write(alt8(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt9ExponentialSmallConcats (cb) {
|
||||
stream.write(alt9(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt0ExponentialLargeConcats (cb) {
|
||||
stream.write(alt0(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt1ExponentialLargeConcats (cb) {
|
||||
stream.write(alt1(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt2ExponentialLargeConcats (cb) {
|
||||
stream.write(alt2(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt3ExponentialLargeConcats (cb) {
|
||||
stream.write(alt3(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt4ExponentialLargeConcats (cb) {
|
||||
stream.write(alt4(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt5ExponentialLargeConcats (cb) {
|
||||
stream.write(alt5(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt6ExponentialLargeConcats (cb) {
|
||||
stream.write(alt6(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt7ExponentialLargeConcats (cb) {
|
||||
stream.write(alt7(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt8ExponentialLargeConcats (cb) {
|
||||
stream.write(alt8(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function alt9ExponentialLargeConcats (cb) {
|
||||
stream.write(alt9(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
}
|
||||
], 10000)
|
||||
|
||||
run(run)
|
||||
|
||||
var rx = /()/
|
||||
function alt1 (s) {
|
||||
rx.test(s)
|
||||
return s
|
||||
}
|
||||
function alt2 (s) {
|
||||
rx.exec(s)
|
||||
return s
|
||||
}
|
||||
|
||||
function alt3 (s) {
|
||||
s | 0
|
||||
return s
|
||||
}
|
||||
|
||||
function alt4 (s) {
|
||||
~s
|
||||
return s
|
||||
}
|
||||
|
||||
function alt5 (s) {
|
||||
escape(s)
|
||||
return s
|
||||
}
|
||||
|
||||
function alt6 (s) {
|
||||
unescape(s)
|
||||
return s
|
||||
}
|
||||
|
||||
function alt7 (s) {
|
||||
parseInt(s, 10)
|
||||
return s
|
||||
}
|
||||
|
||||
function alt8 (s) {
|
||||
parseFloat(s)
|
||||
return s
|
||||
}
|
||||
|
||||
function alt9 (s) {
|
||||
alt9[s] = null
|
||||
return s
|
||||
}
|
||||
|
||||
function makeStr (str, concats) {
|
||||
var s = ''
|
||||
while (concats--) {
|
||||
s += str
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
function makeExpoStr (str, concats) {
|
||||
var s = str
|
||||
while (concats--) {
|
||||
s += s
|
||||
}
|
||||
return s
|
||||
}
|
61
node_modules/flatstr/benchmark.js
generated
vendored
Normal file
61
node_modules/flatstr/benchmark.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use strict'
|
||||
var nul = process.platform === 'win32' ? '\\\\.\\NUL' : '/dev/null'
|
||||
var bench = require('fastbench')
|
||||
var stream = require('fs').createWriteStream(nul)
|
||||
var flatstr = require('./')
|
||||
var largeStr = JSON.stringify(require('./package.json'))
|
||||
largeStr += largeStr
|
||||
largeStr += largeStr
|
||||
|
||||
var run = bench([
|
||||
function unflattenedManySmallConcats (cb) {
|
||||
stream.write(makeStr('a', 200))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function flattenedManySmallConcats (cb) {
|
||||
stream.write(flatstr(makeStr('a', 200)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function unflattenedSeveralLargeConcats (cb) {
|
||||
stream.write(makeStr(largeStr, 10))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function flattenedSeveralLargeConcats (cb) {
|
||||
stream.write(flatstr(makeStr(largeStr, 10)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function unflattenedExponentialSmallConcats (cb) {
|
||||
stream.write(makeExpoStr('a', 12))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function flattenedExponentialSmallConcats (cb) {
|
||||
stream.write(flatstr(makeExpoStr('a', 12)))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function unflattenedExponentialLargeConcats (cb) {
|
||||
stream.write(makeExpoStr(largeStr, 7))
|
||||
setImmediate(cb)
|
||||
},
|
||||
function flattenedExponentialLargeConcats (cb) {
|
||||
stream.write(flatstr(makeExpoStr(largeStr, 7)))
|
||||
setImmediate(cb)
|
||||
}
|
||||
], 10000)
|
||||
|
||||
run(run)
|
||||
|
||||
function makeStr (str, concats) {
|
||||
var s = ''
|
||||
while (concats--) {
|
||||
s += str
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
function makeExpoStr (str, concats) {
|
||||
var s = str
|
||||
while (concats--) {
|
||||
s += s
|
||||
}
|
||||
return s
|
||||
}
|
15
node_modules/flatstr/index.js
generated
vendored
Normal file
15
node_modules/flatstr/index.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
// You may be tempted to copy and paste this,
|
||||
// but take a look at the commit history first,
|
||||
// this is a moving target so relying on the module
|
||||
// is the best way to make sure the optimization
|
||||
// method is kept up to date and compatible with
|
||||
// every Node version.
|
||||
|
||||
function flatstr (s) {
|
||||
s | 0
|
||||
return s
|
||||
}
|
||||
|
||||
module.exports = flatstr
|
58
node_modules/flatstr/package.json
generated
vendored
Normal file
58
node_modules/flatstr/package.json
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"_from": "flatstr@^1.0.12",
|
||||
"_id": "flatstr@1.0.12",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw==",
|
||||
"_location": "/flatstr",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "flatstr@^1.0.12",
|
||||
"name": "flatstr",
|
||||
"escapedName": "flatstr",
|
||||
"rawSpec": "^1.0.12",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.12"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pino",
|
||||
"/sonic-boom"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/flatstr/-/flatstr-1.0.12.tgz",
|
||||
"_shasum": "c2ba6a08173edbb6c9640e3055b95e287ceb5931",
|
||||
"_spec": "flatstr@^1.0.12",
|
||||
"_where": "/home/dawidd6/github/dawidd6/action-debian-package/node_modules/pino",
|
||||
"author": {
|
||||
"name": "David Mark Clements"
|
||||
},
|
||||
"browser": {
|
||||
"v8": "./v8"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/davidmarkclements/flatstr/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Flattens the underlying C structures of a concatenated JavaScript string",
|
||||
"devDependencies": {
|
||||
"fastbench": "^1.0.1",
|
||||
"tap": "^12.0.1"
|
||||
},
|
||||
"homepage": "https://github.com/davidmarkclements/flatstr#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "flatstr",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/davidmarkclements/flatstr.git"
|
||||
},
|
||||
"tags": [
|
||||
"perf",
|
||||
"performance",
|
||||
"strings",
|
||||
"concatenation"
|
||||
],
|
||||
"version": "1.0.12"
|
||||
}
|
82
node_modules/flatstr/readme.md
generated
vendored
Normal file
82
node_modules/flatstr/readme.md
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
# flatstr
|
||||
|
||||
Flattens the underlying C structures of a concatenated JavaScript string
|
||||
|
||||
## About
|
||||
|
||||
If you're doing lots of string concatenation and then writing that
|
||||
string somewhere, you may find that passing your string through
|
||||
`flatstr` vastly improves performance.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var flatstr = require('flatstr')
|
||||
flatstr(someHeavilyConcatenatedString)
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Benchmarks test flat vs non-flat strings being written to
|
||||
an `fs.WriteStream`.
|
||||
|
||||
```
|
||||
unflattenedManySmallConcats*10000: 147.540ms
|
||||
flattenedManySmallConcats*10000: 105.994ms
|
||||
unflattenedSeveralLargeConcats*10000: 287.901ms
|
||||
flattenedSeveralLargeConcats*10000: 226.121ms
|
||||
unflattenedExponentialSmallConcats*10000: 410.533ms
|
||||
flattenedExponentialSmallConcats*10000: 219.973ms
|
||||
unflattenedExponentialLargeConcats*10000: 2774.230ms
|
||||
flattenedExponentialLargeConcats*10000: 1862.815ms
|
||||
```
|
||||
|
||||
In each case, flattened strings win,
|
||||
here's the performance gains from using `flatstr`
|
||||
|
||||
```
|
||||
ManySmallConcats: 28%
|
||||
SeveralLargeConcats: 21%
|
||||
ExponentialSmallConcats: 46%
|
||||
ExponentialLargeConcats: 33%
|
||||
```
|
||||
|
||||
## How does it work
|
||||
|
||||
In the v8 C++ layer, JavaScript strings can be represented in two ways.
|
||||
|
||||
1. As an array
|
||||
2. As a tree
|
||||
|
||||
When JavaScript strings are concatenated, tree structures are used
|
||||
to represent them. For the concat operation, this is cheaper than
|
||||
reallocating a larger array. However, performing other operations
|
||||
on the tree structures can become costly (particularly where lots of
|
||||
concatenation has occurred).
|
||||
|
||||
V8 has a a method called `String::Flatten`which converts the tree into a C array. This method is typically called before operations that walk through the bytes of the string (for instance, when testing against a regular expression). It may also be called if a string is accessed many times over,
|
||||
as an optimization on the string. However, strings aren't always flattened. One example is when we pass a string into a `WriteStream`, at some point the string will be converted to a buffer, and this may be expensive if the underlying representation is a tree.
|
||||
|
||||
`String::Flatten` is not exposed as a JavaScript function, but it can be triggered as a side effect.
|
||||
|
||||
There are several ways to indirectly call `String::Flatten` (see `alt-benchmark.js`),
|
||||
but coercion to a number appears to be (one of) the cheapest.
|
||||
|
||||
However since Node 10 the V8 version has stopped using Flatten in all
|
||||
places identified. Thus the code has been updated to seamlessly
|
||||
use the native runtime function `%FlattenString` without having to use
|
||||
the `--allow-natives-syntax` flag directly.
|
||||
|
||||
One final note: calling flatstr too much can in fact negatively effect performance. For instance, don't call it every time you concat (if that
|
||||
was performant, v8 wouldn't be using trees in the first place). The best
|
||||
place to use flatstr is just prior to passing it to an API that eventually
|
||||
runs non-v8 code (such as `fs.WriteStream`, or perhaps `xhr` or DOM apis in the browser).
|
||||
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
* Sponsored by nearForm
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
26
node_modules/flatstr/test.js
generated
vendored
Normal file
26
node_modules/flatstr/test.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict'
|
||||
var test = require('tap').test
|
||||
var flatstr = require('.')
|
||||
|
||||
test('does not throw', function (t) {
|
||||
t.doesNotThrow(() => {
|
||||
flatstr('abc')
|
||||
})
|
||||
t.doesNotThrow(() => {
|
||||
flatstr({})
|
||||
})
|
||||
t.doesNotThrow(() => {
|
||||
flatstr(1)
|
||||
})
|
||||
t.doesNotThrow(() => {
|
||||
flatstr(null)
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('returns the same value that was passed in', function (t) {
|
||||
var o = {}
|
||||
t.is(flatstr('abc'), 'abc')
|
||||
t.is(flatstr(o), o)
|
||||
t.end()
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue