-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize SQLite WebSockets with msgpackr and Buffer type check …
…fix in recursively parse fn, switch to safe-stable-stringify instead of fast-safe-stringify for majority of use cases (except logger which requires build and has acorn error otherwise), added 50 MB email test, added round trip time to payload, moved attachment body BLOB to last column as optimization (until we move it to foreign db ref), optimize ping/pong conditional check
- Loading branch information
Showing
32 changed files
with
244 additions
and
49 deletions.
There are no files selected for viewing
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
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
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,75 @@ | ||
/** | ||
* Copyright (c) Forward Email LLC | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
const { isNativeAccelerationEnabled, Packr, Unpackr } = require('msgpackr'); | ||
|
||
const logger = require('./logger'); | ||
|
||
// <https://github.com/kriszyp/msgpackr?tab=readme-ov-file#options> | ||
const options = { moreTypes: true }; | ||
|
||
const packr = new Packr(options); | ||
const unpackr = new Unpackr(options); | ||
|
||
// <https://github.com/kriszyp/msgpackr?tab=readme-ov-file#native-acceleration> | ||
if (!isNativeAccelerationEnabled) | ||
logger.fatal( | ||
new TypeError('Native acceleration is not enabled for msgpackr') | ||
); | ||
|
||
/* | ||
// | ||
// NOTE: @msgpack/msgpack is slower than msgpackr | ||
// | ||
const { Encoder, Decoder, ExtensionCodec } = require('@msgpack/msgpack'); | ||
// https://github.com/msgpack/msgpack-javascript?tab=readme-ov-file#extension-types | ||
const extensionCodec = new ExtensionCodec(); | ||
const encoder = new Encoder({ useBigInt64: true, extensionCodec }); | ||
const decoder = new Decoder({ useBigInt64: true, extensionCodec }); | ||
// Set | ||
const SET_EXT_TYPE = 0; // Any in 0-127 | ||
extensionCodec.register({ | ||
type: SET_EXT_TYPE, | ||
encode(object) { | ||
if (object instanceof Set) { | ||
console.log('object was a set', object); | ||
return encoder.encode([...object]); | ||
} | ||
return null; | ||
}, | ||
decode(data) { | ||
const array = decoder.decode(data); | ||
return new Set(array); | ||
} | ||
}); | ||
// Map | ||
const MAP_EXT_TYPE = 1; // Any in 0-127 | ||
extensionCodec.register({ | ||
type: MAP_EXT_TYPE, | ||
encode(object) { | ||
if (object instanceof Map) { | ||
console.log('object was a map', object); | ||
return encoder.encode([...object]); | ||
} | ||
return null; | ||
}, | ||
decode(data) { | ||
const array = decoder.decode(data); | ||
return new Map(array); | ||
} | ||
}); | ||
*/ | ||
|
||
// NOTE: this is extremely slow | ||
// const encoder = { encode: JSON.stringify }; | ||
// const decoder = { decode: JSON.parse }; | ||
|
||
module.exports = { encoder: packr, decoder: unpackr }; |
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
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
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
Oops, something went wrong.