-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compress large JSON requests (#980)
When you deploy or test a project, a potentially very large JSON payload is sent to the API server. In large projects, the time to upload the payload can be quite significant (depending on connection speed). This PR introduces gzip compression to payloads sent to relevant endpoints, which should make the payload easier to upload. Additionally, those large payload were stringified fully in memory, causing unnecessarily high memory usage. This PR changes the payload to be stringified and streamed with json-stream-stringify instead, which should decrease memory usage. This change only applies to requests that are now also getting compressed.
- Loading branch information
Showing
5 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import zlib from 'node:zlib' | ||
|
||
import { AxiosRequestHeaders } from 'axios' | ||
import { JsonStreamStringify } from 'json-stream-stringify' | ||
|
||
export function compressJSONPayload (data: any, headers: AxiosRequestHeaders) { | ||
headers['Content-Type'] = 'application/json' | ||
headers['Content-Encoding'] = 'gzip' | ||
|
||
const zipper = zlib.createGzip() | ||
const streamer = new JsonStreamStringify(data) | ||
|
||
return streamer.pipe(zipper) | ||
} |