Skip to content

Commit

Permalink
adds a mock server, dummy app, and heimdall instrumentation for bench…
Browse files Browse the repository at this point in the history
…marking
  • Loading branch information
runspired committed Sep 14, 2016
1 parent c9d8212 commit f5dc86b
Show file tree
Hide file tree
Showing 56 changed files with 684 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = {
env: {
'browser': true,
},
globals: {
'heimdall': true
},
rules: {
'no-unused-vars': ['error', {
'args': 'none',
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dist/
.idea
*.iml

benchmarks/results/*.json

.DS_Store
.project

Expand Down
4 changes: 4 additions & 0 deletions addon/-private/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function runInDebug() {
return Ember.runInDebug(...arguments);
}

export function instrument() {
return Ember.runInDebug(...arguments);
}

export function warn() {
return Ember.warn(...arguments);
}
Expand Down
31 changes: 29 additions & 2 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ InternalModel.prototype = {

constructor: InternalModel,
materializeRecord() {
let token = heimdall.start('InternalModel._materializeRecord');
assert("Materialized " + this.modelName + " record with id:" + this.id + "more than once", this.record === null || this.record === undefined);

// lookupFactory should really return an object that creates
// instances with the injections applied
let tokenA = heimdall.start('_materializeRecord-createOptions');
var createOptions = {
store: this.store,
_internalModel: this,
Expand All @@ -144,10 +146,13 @@ InternalModel.prototype = {
} else {
createOptions.container = this.store.container;
}

heimdall.stop(tokenA);
tokenA = heimdall.start('_create');
this.record = this.type._create(createOptions);
heimdall.stop(tokenA);

this._triggerDeferredTriggers();
heimdall.stop(token);
},

recordObjectWillDestroy() {
Expand Down Expand Up @@ -222,13 +227,23 @@ InternalModel.prototype = {
},

setupData(data) {
let token = heimdall.start('InternalModel.setupData');
var changedKeys = this._changedKeys(data.attributes);
let tokenA = heimdall.start('setupData-assign');
assign(this._data, data.attributes);
heimdall.stop(tokenA);
tokenA = heimdall.start('setupData-pushedData');
this.pushedData();
heimdall.stop(tokenA);
if (this.record) {
tokenA = heimdall.start('setupData-_notifyProperties');
this.record._notifyProperties(changedKeys);
heimdall.stop(tokenA);
}
tokenA = heimdall.start('setupData-didInitializeData');
this.didInitalizeData();
heimdall.stop(tokenA);
heimdall.stop(token);
},

becameReady() {
Expand All @@ -253,7 +268,11 @@ InternalModel.prototype = {
@private
*/
createSnapshot(options) {
return new Snapshot(this, options);
let token = heimdall.start('new Snapshot()');
let snapshot = new Snapshot(this, options);
heimdall.stop(token);

return snapshot;
},

/*
Expand All @@ -262,6 +281,7 @@ InternalModel.prototype = {
@param {Promise} promise
*/
loadingData(promise) {
// PERF-TODO ELIMINATE
this.send('loadingData', promise);
},

Expand All @@ -270,6 +290,7 @@ InternalModel.prototype = {
@private
*/
loadedData() {
// PERF-TODO ELIMINATE
this.send('loadedData');
this.didInitalizeData();
},
Expand All @@ -279,6 +300,7 @@ InternalModel.prototype = {
@private
*/
notFound() {
// PERF-TODO ELIMINATE
this.send('notFound');
},

Expand All @@ -287,6 +309,7 @@ InternalModel.prototype = {
@private
*/
pushedData() {
// PERF-TODO ELIMINATE
this.send('pushedData');
},

Expand Down Expand Up @@ -371,6 +394,7 @@ InternalModel.prototype = {
@param {Object} context
*/
send(name, context) {
// PERF-TODO optimize send
var currentState = get(this, 'currentState');

if (!currentState[name]) {
Expand Down Expand Up @@ -510,17 +534,20 @@ InternalModel.prototype = {
},

_triggerDeferredTriggers() {
// PERF-TODO remove
//TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record,
//but for now, we queue up all the events triggered before the record was materialized, and flush
//them once we have the record
if (!this.record) {
return;
}
let token = heimdall.start('InternalModel._triggerDefferedTriggers');
for (var i=0, l= this._deferredTriggers.length; i<l; i++) {
this.record.trigger.apply(this.record, this._deferredTriggers[i]);
}

this._deferredTriggers.length = 0;
heimdall.stop(token);
},
/*
@method clearRelationships
Expand Down
1 change: 1 addition & 0 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
data: Ember.computed.readOnly('_internalModel._data'),

//TODO Do we want to deprecate these?
// YES!!!!! - Chris Thoburn
/**
@method send
@private
Expand Down
2 changes: 2 additions & 0 deletions addon/-private/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,13 @@ var DirtyState = {
},

pushedData(internalModel) {
let token = heimdall.start('stats.uncommitted.pushedData');
internalModel.updateChangedAttributes();

if (!internalModel.hasChangedAttributes()) {
internalModel.transitionTo('loaded.saved');
}
heimdall.stop(token);
},

becomeDirty: Ember.K,
Expand Down
19 changes: 18 additions & 1 deletion addon/-private/system/record-array-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export default Ember.Object.extend({
},

recordDidChange(record) {
if (this.changedRecords.push(record) !== 1) { return; }
let token = heimdall.start('recordArrayManager.recordDidChange');
if (this.changedRecords.push(record) !== 1) {
heimdall.stop(token);
return;
}

Ember.run.schedule('actions', this, this.updateRecordArrays);
heimdall.stop(token);
},

recordArraysForRecord(record) {
Expand All @@ -56,6 +61,7 @@ export default Ember.Object.extend({
@method updateRecordArrays
*/
updateRecordArrays() {
let token = heimdall.start('recordArrayManager.updateRecordArrays');
this.changedRecords.forEach((internalModel) => {
if (get(internalModel, 'record.isDestroyed') || get(internalModel, 'record.isDestroying') ||
(get(internalModel, 'currentState.stateName') === 'root.deleted.saved')) {
Expand All @@ -66,6 +72,7 @@ export default Ember.Object.extend({
});

this.changedRecords.length = 0;
heimdall.stop(token);
},

_recordWasDeleted(record) {
Expand Down Expand Up @@ -126,14 +133,17 @@ export default Ember.Object.extend({
},

_addRecordToRecordArray(array, record) {
let token = heimdall.start('RecordArrayManager._addRecordToRecordArray');
var recordArrays = this.recordArraysForRecord(record);
if (!recordArrays.has(array)) {
array.addInternalModel(record);
recordArrays.add(array);
}
heimdall.stop(token);
},

populateLiveRecordArray(array, modelName) {
let token = heimdall.start('RecordArrayManager.populateLiveRecordArray');
var typeMap = this.store.typeMapFor(modelName);
var records = typeMap.records;
var record;
Expand All @@ -145,6 +155,7 @@ export default Ember.Object.extend({
this._addRecordToRecordArray(array, record);
}
}
heimdall.stop(token);
},

/**
Expand Down Expand Up @@ -193,6 +204,7 @@ export default Ember.Object.extend({
@return {DS.RecordArray}
*/
createRecordArray(typeClass) {
let token = heimdall.start('RecordArrayManager.createRecordArray');
var array = RecordArray.create({
type: typeClass,
content: Ember.A(),
Expand All @@ -201,6 +213,7 @@ export default Ember.Object.extend({
manager: this
});

heimdall.stop(token);
return array;
},

Expand All @@ -214,6 +227,7 @@ export default Ember.Object.extend({
@return {DS.FilteredRecordArray}
*/
createFilteredRecordArray(typeClass, filter, query) {
let token = heimdall.start('RecordArrayManager.createFilteredRecordArray');
var array = FilteredRecordArray.create({
query: query,
type: typeClass,
Expand All @@ -225,6 +239,7 @@ export default Ember.Object.extend({

this.registerFilteredRecordArray(array, typeClass, filter);

heimdall.stop(token);
return array;
},

Expand All @@ -237,6 +252,7 @@ export default Ember.Object.extend({
@return {DS.AdapterPopulatedRecordArray}
*/
createAdapterPopulatedRecordArray(typeClass, query) {
let token = heimdall.start('RecordArrayManager.createAdapterPopulatedRecordArray');
var array = AdapterPopulatedRecordArray.create({
type: typeClass,
query: query,
Expand All @@ -247,6 +263,7 @@ export default Ember.Object.extend({

this._adapterPopulatedRecordArrays.push(array);

heimdall.stop(token);
return array;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default RecordArray.extend({
@private
*/
loadRecords(records, payload) {
let token = heimdall.start('AdapterPopulatedRecordArray.loadRecords');
//TODO Optimize
var internalModels = Ember.A(records).mapBy('_internalModel');
this.setProperties({
Expand All @@ -61,5 +62,6 @@ export default RecordArray.extend({

// TODO: should triggering didLoad event be the last action of the runLoop?
Ember.run.once(this, 'trigger', 'didLoad');
heimdall.stop(token);
}
});
13 changes: 13 additions & 0 deletions addon/-private/system/relationships/state/relationship.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
/* global heimdall */
import Ember from 'ember';
import { assert, warn } from "ember-data/-private/debug";
import OrderedSet from "ember-data/-private/system/ordered-set";

const [ __a, __b ] = heimdall.registerMonitor('system.relationships.state.relationship',
'new',
'updateMeta',
'clear',
'removeRecords',
'addRecords',
'addCanonicalRecords',
'addRecord',
'addCanonicalRecord',
'flushCanonical'
);

export default function Relationship(store, record, inverseKey, relationshipMeta) {
var async = relationshipMeta.options.async;
this.members = new OrderedSet();
Expand Down
Loading

0 comments on commit f5dc86b

Please sign in to comment.