You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Make re-emitting events much more memory efficient
The previous impl bluntly created a closure for every event type and source emitter we set up a re-emit for. We can do much better than this fairly easily by having one bound handler for each event name and moving it into a class so we have one emitter per target, since 99% of the time the target is the client object.
This commit is contained in:
@@ -40,7 +40,7 @@ const SyncApi = require("./sync");
|
||||
const MatrixBaseApis = require("./base-apis");
|
||||
const MatrixError = httpApi.MatrixError;
|
||||
|
||||
import reEmit from './reemit';
|
||||
import ReEmitter from './ReEmitter';
|
||||
|
||||
const SCROLLBACK_DELAY_MS = 3000;
|
||||
let CRYPTO_ENABLED = false;
|
||||
@@ -115,6 +115,8 @@ try {
|
||||
function MatrixClient(opts) {
|
||||
MatrixBaseApis.call(this, opts);
|
||||
|
||||
this.reEmitter = new ReEmitter(this);
|
||||
|
||||
this.store = opts.store || new StubStore();
|
||||
|
||||
this.deviceId = opts.deviceId || null;
|
||||
@@ -364,7 +366,7 @@ MatrixClient.prototype.initCrypto = async function() {
|
||||
this._cryptoStore,
|
||||
);
|
||||
|
||||
reEmit(this, crypto, [
|
||||
this.reEmitter.reEmit(crypto, [
|
||||
"crypto.roomKeyRequest",
|
||||
"crypto.roomKeyRequestCancellation",
|
||||
]);
|
||||
@@ -3275,7 +3277,7 @@ function _PojoToMatrixEventMapper(client) {
|
||||
function mapper(plainOldJsObject) {
|
||||
const event = new MatrixEvent(plainOldJsObject);
|
||||
if (event.isEncrypted()) {
|
||||
reEmit(client, event, [
|
||||
client.reEmitter.reEmit(event, [
|
||||
"Event.decrypted",
|
||||
]);
|
||||
event.attemptDecryption(client._crypto);
|
||||
|
||||
Reference in New Issue
Block a user