Skip to content

Commit 3c23eea

Browse files
authored
Got 12 improvements (sindresorhus#1667)
1 parent 4cce4de commit 3c23eea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4106
-3814
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ yarn.lock
33
coverage
44
.nyc_output
55
dist
6+
*.0x

benchmark/index.ts

+53-19
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ import * as Benchmark from 'benchmark';
55
import fetch from 'node-fetch';
66
import * as request from 'request';
77
import got from '../source/index';
8-
import Request, {kIsNormalizedAlready} from '../source/core/index';
9-
10-
const {normalizeArguments} = Request;
8+
import Request from '../source/core/index';
9+
import Options, {OptionsInit} from '../source/core/options';
1110

1211
// Configuration
1312
const httpsAgent = new https.Agent({
1413
keepAlive: true,
1514
rejectUnauthorized: false
1615
});
1716

18-
const url = new URL('https://127.0.0.1:8080');
17+
const url = new URL('https://127.0.0.1:8081');
1918
const urlString = url.toString();
2019

21-
const gotOptions = {
20+
const gotOptions: OptionsInit & {isStream?: true} = {
2221
agent: {
2322
https: httpsAgent
2423
},
25-
https: {
24+
httpsOptions: {
2625
rejectUnauthorized: false
2726
},
28-
retry: 0
27+
retry: {
28+
limit: 0
29+
}
2930
};
3031

31-
const normalizedGotOptions = normalizeArguments(url, gotOptions);
32-
normalizedGotOptions[kIsNormalizedAlready] = true;
32+
const normalizedGotOptions = new Options(url, gotOptions);
3333

3434
const requestOptions = {
3535
strictSSL: false,
@@ -80,6 +80,7 @@ suite.add('got - promise', {
8080
defer: true,
8181
fn: async (deferred: {resolve: () => void}) => {
8282
const stream = new Request(url, gotOptions);
83+
void stream.flush();
8384
stream.resume().once('end', () => {
8485
deferred.resolve();
8586
});
@@ -88,6 +89,7 @@ suite.add('got - promise', {
8889
defer: true,
8990
fn: async (deferred: {resolve: () => void}) => {
9091
const stream = new Request(undefined as any, normalizedGotOptions);
92+
void stream.flush();
9193
stream.resume().once('end', () => {
9294
deferred.resolve();
9395
});
@@ -169,7 +171,8 @@ const internalBenchmark = (): void => {
169171
const internalSuite = new Benchmark.Suite();
170172
internalSuite.add('got - normalize options', {
171173
fn: () => {
172-
normalizeArguments(url, gotOptions);
174+
// eslint-disable-next-line no-new
175+
new Options(url, gotOptions);
173176
}
174177
}).on('cycle', (event: Benchmark.Event) => {
175178
console.log(String(event.target));
@@ -179,17 +182,48 @@ const internalBenchmark = (): void => {
179182
};
180183

181184
// Results (i7-7700k, CPU governor: performance):
185+
186+
// e9359d3fa0cb40324f2b84364408b3f9f7ff2cee (Rewrite Got #1051) - unknown Node.js version
187+
// got - promise x 3,092 ops/sec ±5.25% (73 runs sampled)
188+
// got - stream x 4,313 ops/sec ±5.61% (72 runs sampled)
189+
// got - promise core x 6,756 ops/sec ±5.32% (80 runs sampled)
190+
// got - stream core x 6,863 ops/sec ±4.68% (76 runs sampled)
191+
// got - stream core - normalized options x 7,960 ops/sec ±3.83% (81 runs sampled)
192+
193+
// b927e2d028ecc023bf7eff2702ffb5c72016a85a (Fix bugs, increase coverage, update benchmark results) - unknown Node.js version
194+
// got - promise x 3,204 ops/sec ±5.27% (73 runs sampled)
195+
// got - stream x 5,045 ops/sec ±3.85% (77 runs sampled)
196+
// got - promise core x 6,499 ops/sec ±3.67% (77 runs sampled)
197+
// got - stream core x 7,047 ops/sec ±2.32% (83 runs sampled)
198+
// got - stream core - normalized options x 7,313 ops/sec ±2.79% (85 runs sampled)
199+
200+
// 7e8898e9095e7da52e4ff342606cfd1dc5186f54 (Merge PromisableRequest into Request) - unknown Node.js version
182201
// got - promise x 3,003 ops/sec ±6.26% (70 runs sampled)
183202
// got - stream x 3,538 ops/sec ±5.86% (67 runs sampled)
184203
// got - core x 5,828 ops/sec ±3.11% (79 runs sampled)
185204
// got - core - normalized options x 7,596 ops/sec ±1.60% (85 runs sampled)
186-
// request - callback x 6,530 ops/sec ±6.84% (72 runs sampled)
187-
// request - stream x 7,348 ops/sec ±3.62% (78 runs sampled)
188-
// node-fetch - promise x 6,284 ops/sec ±5.50% (76 runs sampled)
189-
// node-fetch - stream x 7,746 ops/sec ±3.32% (80 runs sampled)
190-
// axios - promise x 6,301 ops/sec ±6.24% (77 runs sampled)
191-
// axios - stream x 8,605 ops/sec ±2.73% (87 runs sampled)
192-
// https - stream x 10,477 ops/sec ±3.64% (80 runs sampled)
193-
// Fastest is https - stream
194205

195-
// got - normalize options x 90,974 ops/sec ±0.57% (93 runs sampled)
206+
// [main] - Node.js v15.10.0
207+
// got - promise x 3,201 ops/sec ±5.24% (67 runs sampled)
208+
// got - stream x 3,633 ops/sec ±4.06% (74 runs sampled)
209+
// got - core x 4,382 ops/sec ±3.26% (77 runs sampled)
210+
// got - core - normalized options x 5,470 ops/sec ±3.70% (78 runs sampled)
211+
212+
// v12 - Node.js v15.10.0
213+
// got - promise x 3,492 ops/sec ±5.13% (71 runs sampled)
214+
// got - stream x 4,772 ops/sec ±1.52% (84 runs sampled)
215+
// got - core x 4,990 ops/sec ±1.14% (83 runs sampled)
216+
// got - core - normalized options x 5,386 ops/sec ±0.52% (87 runs sampled)
217+
218+
// got - normalize options x 117,810 ops/sec ±0.36% (97 runs sampled)
219+
220+
// ================================================================================
221+
222+
// request - callback x 6,448 ops/sec ±5.76% (67 runs sampled)
223+
// request - stream x 7,115 ops/sec ±2.85% (83 runs sampled)
224+
// node-fetch - promise x 6,236 ops/sec ±5.56% (75 runs sampled)
225+
// node-fetch - stream x 7,225 ops/sec ±2.10% (81 runs sampled)
226+
// axios - promise x 5,620 ops/sec ±3.13% (78 runs sampled)
227+
// axios - stream x 7,244 ops/sec ±3.31% (80 runs sampled)
228+
// https - stream x 8,588 ops/sec ±5.50% (61 runs sampled)
229+
// Fastest is https - stream

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"cacheable-lookup": "^6.0.0",
5151
"cacheable-request": "^7.0.1",
5252
"decompress-response": "^6.0.0",
53-
"http2-wrapper": "^2.0.0",
53+
"get-stream": "^6.0.0",
54+
"http2-wrapper": "^2.0.1",
5455
"lowercase-keys": "^2.0.0",
5556
"p-cancelable": "^2.0.0",
5657
"responselike": "^2.0.0"
@@ -78,7 +79,6 @@
7879
"delay": "^5.0.0",
7980
"express": "^4.17.1",
8081
"form-data": "^4.0.0",
81-
"get-stream": "^6.0.0",
8282
"nock": "^13.0.7",
8383
"node-fetch": "^2.6.1",
8484
"np": "^7.4.0",
@@ -137,7 +137,8 @@
137137
"import/no-anonymous-default-export": "off",
138138
"@typescript-eslint/no-implicit-any-catch": "off",
139139
"unicorn/import-index": "off",
140-
"import/no-useless-path-segments": "off"
140+
"import/no-useless-path-segments": "off",
141+
"import/no-named-as-default": "off"
141142
}
142143
},
143144
"runkitExampleFilename": "./documentation/examples/runkit-example.js"

source/as-promise/create-rejection.ts

-31
This file was deleted.

0 commit comments

Comments
 (0)