From 874020ced76d39a8b606a8ef7893c3a9000838b3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 20 Feb 2018 17:49:25 +0000 Subject: [PATCH] Make Events create Dates on demand My test account had 37MB (shallow) of Date objects knocking around in memory. This gets rid of them. I can't see any appreciable difference in the time taken to switch rooms (where now we recreate a bunch of Dates that previously would have been cached). --- src/models/event.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/models/event.js b/src/models/event.js index 50474e51170..d8cd34c0c59 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -108,8 +108,6 @@ module.exports.MatrixEvent = function MatrixEvent( this.error = null; this.forwardLooking = true; this._pushActions = null; - this._date = this.event.origin_server_ts ? - new Date(this.event.origin_server_ts) : null; this._clearEvent = {}; @@ -204,7 +202,7 @@ utils.extend(module.exports.MatrixEvent.prototype, { * @return {Date} The event date, e.g. new Date(1433502692297) */ getDate: function() { - return this._date; + return this.event.origin_server_ts ? new Date(this.event.origin_server_ts) : null; }, /** @@ -652,7 +650,6 @@ utils.extend(module.exports.MatrixEvent.prototype, { this.event = event; // successfully sent. this.status = null; - this._date = new Date(this.event.origin_server_ts); }, });