source: imaps-frontend/node_modules/@jridgewell/sourcemap-codec/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 9.8 KB
RevLine 
[d565449]1# @jridgewell/sourcemap-codec
2
3Encode/decode the `mappings` property of a [sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit).
4
5
6## Why?
7
8Sourcemaps are difficult to generate and manipulate, because the `mappings` property – the part that actually links the generated code back to the original source – is encoded using an obscure method called [Variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity). On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap.
9
10This package makes the process slightly easier.
11
12
13## Installation
14
15```bash
16npm install @jridgewell/sourcemap-codec
17```
18
19
20## Usage
21
22```js
23import { encode, decode } from '@jridgewell/sourcemap-codec';
24
25var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );
26
27assert.deepEqual( decoded, [
28 // the first line (of the generated code) has no mappings,
29 // as shown by the starting semi-colon (which separates lines)
30 [],
31
32 // the second line contains four (comma-separated) segments
33 [
34 // segments are encoded as you'd expect:
35 // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]
36
37 // i.e. the first segment begins at column 2, and maps back to the second column
38 // of the second line (both zero-based) of the 0th source, and uses the 0th
39 // name in the `map.names` array
40 [ 2, 0, 2, 2, 0 ],
41
42 // the remaining segments are 4-length rather than 5-length,
43 // because they don't map a name
44 [ 4, 0, 2, 4 ],
45 [ 6, 0, 2, 5 ],
46 [ 7, 0, 2, 7 ]
47 ],
48
49 // the final line contains two segments
50 [
51 [ 2, 1, 10, 19 ],
52 [ 12, 1, 11, 20 ]
53 ]
54]);
55
56var encoded = encode( decoded );
57assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );
58```
59
60## Benchmarks
61
62```
63node v20.10.0
64
65amp.js.map - 45120 segments
66
67Decode Memory Usage:
68local code 5815135 bytes
69@jridgewell/sourcemap-codec 1.4.15 5868160 bytes
70sourcemap-codec 5492584 bytes
71source-map-0.6.1 13569984 bytes
72source-map-0.8.0 6390584 bytes
73chrome dev tools 8011136 bytes
74Smallest memory usage is sourcemap-codec
75
76Decode speed:
77decode: local code x 492 ops/sec ±1.22% (90 runs sampled)
78decode: @jridgewell/sourcemap-codec 1.4.15 x 499 ops/sec ±1.16% (89 runs sampled)
79decode: sourcemap-codec x 376 ops/sec ±1.66% (89 runs sampled)
80decode: source-map-0.6.1 x 34.99 ops/sec ±0.94% (48 runs sampled)
81decode: source-map-0.8.0 x 351 ops/sec ±0.07% (95 runs sampled)
82chrome dev tools x 165 ops/sec ±0.91% (86 runs sampled)
83Fastest is decode: @jridgewell/sourcemap-codec 1.4.15
84
85Encode Memory Usage:
86local code 444248 bytes
87@jridgewell/sourcemap-codec 1.4.15 623024 bytes
88sourcemap-codec 8696280 bytes
89source-map-0.6.1 8745176 bytes
90source-map-0.8.0 8736624 bytes
91Smallest memory usage is local code
92
93Encode speed:
94encode: local code x 796 ops/sec ±0.11% (97 runs sampled)
95encode: @jridgewell/sourcemap-codec 1.4.15 x 795 ops/sec ±0.25% (98 runs sampled)
96encode: sourcemap-codec x 231 ops/sec ±0.83% (86 runs sampled)
97encode: source-map-0.6.1 x 166 ops/sec ±0.57% (86 runs sampled)
98encode: source-map-0.8.0 x 203 ops/sec ±0.45% (88 runs sampled)
99Fastest is encode: local code,encode: @jridgewell/sourcemap-codec 1.4.15
100
101
102***
103
104
105babel.min.js.map - 347793 segments
106
107Decode Memory Usage:
108local code 35424960 bytes
109@jridgewell/sourcemap-codec 1.4.15 35424696 bytes
110sourcemap-codec 36033464 bytes
111source-map-0.6.1 62253704 bytes
112source-map-0.8.0 43843920 bytes
113chrome dev tools 45111400 bytes
114Smallest memory usage is @jridgewell/sourcemap-codec 1.4.15
115
116Decode speed:
117decode: local code x 38.18 ops/sec ±5.44% (52 runs sampled)
118decode: @jridgewell/sourcemap-codec 1.4.15 x 38.36 ops/sec ±5.02% (52 runs sampled)
119decode: sourcemap-codec x 34.05 ops/sec ±4.45% (47 runs sampled)
120decode: source-map-0.6.1 x 4.31 ops/sec ±2.76% (15 runs sampled)
121decode: source-map-0.8.0 x 55.60 ops/sec ±0.13% (73 runs sampled)
122chrome dev tools x 16.94 ops/sec ±3.78% (46 runs sampled)
123Fastest is decode: source-map-0.8.0
124
125Encode Memory Usage:
126local code 2606016 bytes
127@jridgewell/sourcemap-codec 1.4.15 2626440 bytes
128sourcemap-codec 21152576 bytes
129source-map-0.6.1 25023928 bytes
130source-map-0.8.0 25256448 bytes
131Smallest memory usage is local code
132
133Encode speed:
134encode: local code x 127 ops/sec ±0.18% (83 runs sampled)
135encode: @jridgewell/sourcemap-codec 1.4.15 x 128 ops/sec ±0.26% (83 runs sampled)
136encode: sourcemap-codec x 29.31 ops/sec ±2.55% (53 runs sampled)
137encode: source-map-0.6.1 x 18.85 ops/sec ±3.19% (36 runs sampled)
138encode: source-map-0.8.0 x 19.34 ops/sec ±1.97% (36 runs sampled)
139Fastest is encode: @jridgewell/sourcemap-codec 1.4.15
140
141
142***
143
144
145preact.js.map - 1992 segments
146
147Decode Memory Usage:
148local code 261696 bytes
149@jridgewell/sourcemap-codec 1.4.15 244296 bytes
150sourcemap-codec 302816 bytes
151source-map-0.6.1 939176 bytes
152source-map-0.8.0 336 bytes
153chrome dev tools 587368 bytes
154Smallest memory usage is source-map-0.8.0
155
156Decode speed:
157decode: local code x 17,782 ops/sec ±0.32% (97 runs sampled)
158decode: @jridgewell/sourcemap-codec 1.4.15 x 17,863 ops/sec ±0.40% (100 runs sampled)
159decode: sourcemap-codec x 12,453 ops/sec ±0.27% (101 runs sampled)
160decode: source-map-0.6.1 x 1,288 ops/sec ±1.05% (96 runs sampled)
161decode: source-map-0.8.0 x 9,289 ops/sec ±0.27% (101 runs sampled)
162chrome dev tools x 4,769 ops/sec ±0.18% (100 runs sampled)
163Fastest is decode: @jridgewell/sourcemap-codec 1.4.15
164
165Encode Memory Usage:
166local code 262944 bytes
167@jridgewell/sourcemap-codec 1.4.15 25544 bytes
168sourcemap-codec 323048 bytes
169source-map-0.6.1 507808 bytes
170source-map-0.8.0 507480 bytes
171Smallest memory usage is @jridgewell/sourcemap-codec 1.4.15
172
173Encode speed:
174encode: local code x 24,207 ops/sec ±0.79% (95 runs sampled)
175encode: @jridgewell/sourcemap-codec 1.4.15 x 24,288 ops/sec ±0.48% (96 runs sampled)
176encode: sourcemap-codec x 6,761 ops/sec ±0.21% (100 runs sampled)
177encode: source-map-0.6.1 x 5,374 ops/sec ±0.17% (99 runs sampled)
178encode: source-map-0.8.0 x 5,633 ops/sec ±0.32% (99 runs sampled)
179Fastest is encode: @jridgewell/sourcemap-codec 1.4.15,encode: local code
180
181
182***
183
184
185react.js.map - 5726 segments
186
187Decode Memory Usage:
188local code 678816 bytes
189@jridgewell/sourcemap-codec 1.4.15 678816 bytes
190sourcemap-codec 816400 bytes
191source-map-0.6.1 2288864 bytes
192source-map-0.8.0 721360 bytes
193chrome dev tools 1012512 bytes
194Smallest memory usage is local code
195
196Decode speed:
197decode: local code x 6,178 ops/sec ±0.19% (98 runs sampled)
198decode: @jridgewell/sourcemap-codec 1.4.15 x 6,261 ops/sec ±0.22% (100 runs sampled)
199decode: sourcemap-codec x 4,472 ops/sec ±0.90% (99 runs sampled)
200decode: source-map-0.6.1 x 449 ops/sec ±0.31% (95 runs sampled)
201decode: source-map-0.8.0 x 3,219 ops/sec ±0.13% (100 runs sampled)
202chrome dev tools x 1,743 ops/sec ±0.20% (99 runs sampled)
203Fastest is decode: @jridgewell/sourcemap-codec 1.4.15
204
205Encode Memory Usage:
206local code 140960 bytes
207@jridgewell/sourcemap-codec 1.4.15 159808 bytes
208sourcemap-codec 969304 bytes
209source-map-0.6.1 930520 bytes
210source-map-0.8.0 930248 bytes
211Smallest memory usage is local code
212
213Encode speed:
214encode: local code x 8,013 ops/sec ±0.19% (100 runs sampled)
215encode: @jridgewell/sourcemap-codec 1.4.15 x 7,989 ops/sec ±0.20% (101 runs sampled)
216encode: sourcemap-codec x 2,472 ops/sec ±0.21% (99 runs sampled)
217encode: source-map-0.6.1 x 2,200 ops/sec ±0.17% (99 runs sampled)
218encode: source-map-0.8.0 x 2,220 ops/sec ±0.37% (99 runs sampled)
219Fastest is encode: local code
220
221
222***
223
224
225vscode.map - 2141001 segments
226
227Decode Memory Usage:
228local code 198955264 bytes
229@jridgewell/sourcemap-codec 1.4.15 199175352 bytes
230sourcemap-codec 199102688 bytes
231source-map-0.6.1 386323432 bytes
232source-map-0.8.0 244116432 bytes
233chrome dev tools 293734280 bytes
234Smallest memory usage is local code
235
236Decode speed:
237decode: local code x 3.90 ops/sec ±22.21% (15 runs sampled)
238decode: @jridgewell/sourcemap-codec 1.4.15 x 3.95 ops/sec ±23.53% (15 runs sampled)
239decode: sourcemap-codec x 3.82 ops/sec ±17.94% (14 runs sampled)
240decode: source-map-0.6.1 x 0.61 ops/sec ±7.81% (6 runs sampled)
241decode: source-map-0.8.0 x 9.54 ops/sec ±0.28% (28 runs sampled)
242chrome dev tools x 2.18 ops/sec ±10.58% (10 runs sampled)
243Fastest is decode: source-map-0.8.0
244
245Encode Memory Usage:
246local code 13509880 bytes
247@jridgewell/sourcemap-codec 1.4.15 13537648 bytes
248sourcemap-codec 32540104 bytes
249source-map-0.6.1 127531040 bytes
250source-map-0.8.0 127535312 bytes
251Smallest memory usage is local code
252
253Encode speed:
254encode: local code x 20.10 ops/sec ±0.19% (38 runs sampled)
255encode: @jridgewell/sourcemap-codec 1.4.15 x 20.26 ops/sec ±0.32% (38 runs sampled)
256encode: sourcemap-codec x 5.44 ops/sec ±1.64% (18 runs sampled)
257encode: source-map-0.6.1 x 2.30 ops/sec ±4.79% (10 runs sampled)
258encode: source-map-0.8.0 x 2.46 ops/sec ±6.53% (10 runs sampled)
259Fastest is encode: @jridgewell/sourcemap-codec 1.4.15
260```
261
262# License
263
264MIT
Note: See TracBrowser for help on using the repository browser.