@jridgewell/trace-mapping
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -104,3 +104,3 @@ (function (global, factory) { | ||
this._lastColumn = 0; | ||
this._mappings = maybeSort$1(map.mappings, owned); | ||
this._mappings = maybeSort(map.mappings, owned); | ||
} | ||
@@ -127,3 +127,3 @@ encodedMappings() { | ||
} | ||
function maybeSort$1(mappings, owned) { | ||
function maybeSort(mappings, owned) { | ||
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0); | ||
@@ -143,3 +143,3 @@ if (unsortedIndex === mappings.length) | ||
for (let i = start; i < mappings.length; i++) { | ||
if (!isSorted$1(mappings[i])) | ||
if (!isSorted(mappings[i])) | ||
return i; | ||
@@ -149,3 +149,3 @@ } | ||
} | ||
function isSorted$1(line) { | ||
function isSorted(line) { | ||
for (let j = 1; j < line.length; j++) { | ||
@@ -185,2 +185,3 @@ if (line[j][0] < line[j - 1][0]) { | ||
let namesIndex = 1; | ||
let lineSorted = true; | ||
// count tracks the number of segments we have stored. | ||
@@ -204,3 +205,5 @@ let count = 0; | ||
lines.push(count); | ||
maybeSort(decoded, lastLineStart, count); | ||
if (!lineSorted) | ||
easySort(decoded, lastLineStart, count); | ||
lineSorted = true; | ||
lastLineStart = count; | ||
@@ -217,2 +220,4 @@ // generatedColumn is reset when the next line starts, per the spec. | ||
pos = decodeInteger(encoded, pos, decoded, count); | ||
if (lineSorted) | ||
lineSorted = decoded[count] < 0; | ||
generatedColumn = decoded[count] += generatedColumn; | ||
@@ -247,3 +252,4 @@ count++; | ||
lines.push(count); | ||
maybeSort(decoded, lastLineStart, count); | ||
if (!lineSorted) | ||
easySort(decoded, lastLineStart, count); | ||
return decoded.subarray(0, count); | ||
@@ -288,5 +294,3 @@ } | ||
} | ||
function maybeSort(state, start, end) { | ||
if (isSorted(state, start, end)) | ||
return; | ||
function easySort(state, start, end) { | ||
// This isn't a fast algorithm, but I believe it's exceedingly rare for a mapping to be unsorted. | ||
@@ -302,9 +306,2 @@ const segments = []; | ||
} | ||
function isSorted(state, start, end) { | ||
for (let i = start + ITEM_LENGTH; i < end; i += ITEM_LENGTH) { | ||
if (state[i] < state[i - ITEM_LENGTH]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
function sortComparator(a, b) { | ||
@@ -311,0 +308,0 @@ return a[0] - b[0]; |
{ | ||
"name": "@jridgewell/trace-mapping", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Trace the original position through a source map", | ||
@@ -52,4 +52,5 @@ "keywords": [ | ||
"ava": "4.0.1", | ||
"benchmark": "2.1.4", | ||
"c8": "7.11.0", | ||
"esbuild": "0.14.11", | ||
"esbuild": "0.14.14", | ||
"esbuild-node-loader": "0.6.4", | ||
@@ -61,2 +62,4 @@ "eslint": "8.7.0", | ||
"rollup": "2.64.0", | ||
"source-map": "0.6.1", | ||
"source-map-js": "1.0.2", | ||
"tslib": "2.3.1", | ||
@@ -63,0 +66,0 @@ "typescript": "4.5.4" |
@@ -52,2 +52,26 @@ # @jridgewell/trace-mapping | ||
## Benchmarks | ||
`trace-mapping` is the fastest source map tracing library, by a factor of 4-5x when | ||
constructing/parsing source maps and another 4-5x when using `originalPositionFor` on an already | ||
constructed instance. | ||
``` | ||
node v16.13.2 | ||
trace-mapping: decoded JSON input x 4,224 ops/sec ±0.23% (98 runs sampled) | ||
trace-mapping: encoded JSON input x 4,803 ops/sec ±0.38% (99 runs sampled) | ||
trace-mapping: decoded Object input x 105,471 ops/sec ±0.10% (100 runs sampled) | ||
trace-mapping: encoded Object input x 4,913 ops/sec ±0.36% (100 runs sampled) | ||
source-map-js: encoded Object input x 3,610 ops/sec ±0.24% (97 runs sampled) | ||
source-map: encoded Object input x 1,467 ops/sec ±0.22% (97 runs sampled) | ||
Fastest is trace-mapping: decoded Object input | ||
trace-mapping: encoded originalPositionFor x 7,704 ops/sec ±0.19% (101 runs sampled) | ||
trace-mapping: decoded originalPositionFor x 7,588 ops/sec ±0.09% (101 runs sampled) | ||
source-map-js: encoded originalPositionFor x 1,657 ops/sec ±0.18% (100 runs sampled) | ||
source-map: encoded originalPositionFor x 927 ops/sec ±0.28% (99 runs sampled) | ||
Fastest is trace-mapping: encoded originalPositionFor | ||
``` | ||
[source-map]: https://www.npmjs.com/package/source-map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
70272
77
17
994