mongoose: Severe performance regression in 3.8.14
The fix for #2140 (cdd63bf6ff0854018cd6b70fd8397c9e942dcd59) introduced a quite severe performance regression.
Compare the runtime of this code sample with mongoose 3.8.13 and 4.7.2:
var mongoose = require('mongoose')
var fs = require('fs')
var Schema = mongoose.Schema;
ChecklistSchema = new Schema({
name: { type: String }
});
BoardSchema = new Schema({
checklists: { type: [ChecklistSchema] }
});
var Board = mongoose.model('Board', BoardSchema);
var doc = new Board();
for (var i = 0; i < 1000; ++i) {
var checklist = {name:'test'};
doc.checklists.push(checklist);
}
var obj = doc.toObject();
var time2 = 0;
var start2 = new Date();
for (var i = 0; i < 100; i++) {
new Board(obj);
}
console.error('instantiating schema object took %d ms', (new Date - start2));
sebastian@host:~/Desktop/test$ node big # mongoose 3.8.13
instantiating schema object took 1127 ms
sebastian@host:~/Desktop/test$ node big # mongoose 4.7.3
instantiating schema object took 6898 ms
So at this point I think itโd be better to either make .id
properly handle a null subdoc, or alternatively loop through all subdocs before calling id and checking for null first (and then avoid calling .id
if any are found).
Node v6.9.2 mongoose 4.7.3
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (4 by maintainers)
Commits related to this issue
- perf: remove try/catch that kills optimizer Re: #4821 — committed to Automattic/mongoose by vkarpov15 8 years ago
- perf(document): remove some reduce and forEach to speed up #4821 — committed to Automattic/mongoose by vkarpov15 8 years ago
Using the head of this branch as it stands right now is now much faster than 3.8.40, will release that as part of 4.8
๐