From f723f5c1a37d94441465dcbfdde8226dc97f5050 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 5 Sep 2022 17:27:57 -0700 Subject: [PATCH] add more perf tests --- .../app/router.js | 2 + .../routes/add-children-then-materialize.js | 44 ++++++++++++++++ .../routes/add-children-to-materialized.js | 52 +++++++++++++++++++ .../app/templates/application.hbs | 2 + 4 files changed, 100 insertions(+) create mode 100644 packages/unpublished-relationship-performance-test-app/app/routes/add-children-then-materialize.js create mode 100644 packages/unpublished-relationship-performance-test-app/app/routes/add-children-to-materialized.js diff --git a/packages/unpublished-relationship-performance-test-app/app/router.js b/packages/unpublished-relationship-performance-test-app/app/router.js index 305c395cb1d..76d21738501 100644 --- a/packages/unpublished-relationship-performance-test-app/app/router.js +++ b/packages/unpublished-relationship-performance-test-app/app/router.js @@ -12,6 +12,8 @@ Router.map(function () { this.route('relationship-materialization-simple'); this.route('relationship-materialization-complex'); this.route('add-children'); + this.route('add-children-then-materialize'); + this.route('add-children-to-materialized'); this.route('unload'); this.route('unload-all'); this.route('destroy'); diff --git a/packages/unpublished-relationship-performance-test-app/app/routes/add-children-then-materialize.js b/packages/unpublished-relationship-performance-test-app/app/routes/add-children-then-materialize.js new file mode 100644 index 00000000000..87267bb99bc --- /dev/null +++ b/packages/unpublished-relationship-performance-test-app/app/routes/add-children-then-materialize.js @@ -0,0 +1,44 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; + +export default Route.extend({ + store: service(), + + async model() { + performance.mark('start-data-generation'); + + const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json()); + const updatePayload = await fetch('./fixtures/add-children-final.json').then((r) => r.json()); + + performance.mark('start-push-initial-payload'); + this.store.push(initialPayload); + + performance.mark('start-push-update-payload'); + this.store.push(updatePayload); + + performance.mark('start-materialize-records'); + const peekedParents = this.store.peekAll('parent').slice(); + this.store.peekAll('child').slice(); + + performance.mark('start-materialize-relationships'); + let seen = new Set(); + peekedParents.forEach((parent) => iterateParent(parent, seen)); + + performance.mark('end-materialize-relationships'); + }, +}); + +function iterateChild(record, seen) { + if (seen.has(record)) { + return; + } + seen.add(record); + // record.parent.get('name'); + record.bestFriend.get('name'); + record.secondBestFriend.get('name'); + record.friends.forEach((child) => iterateChild(child, seen)); +} +function iterateParent(record, seen) { + seen.add(record); + record.children.forEach((child) => iterateChild(child, seen)); +} diff --git a/packages/unpublished-relationship-performance-test-app/app/routes/add-children-to-materialized.js b/packages/unpublished-relationship-performance-test-app/app/routes/add-children-to-materialized.js new file mode 100644 index 00000000000..93ba22676d0 --- /dev/null +++ b/packages/unpublished-relationship-performance-test-app/app/routes/add-children-to-materialized.js @@ -0,0 +1,52 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; + +export default Route.extend({ + store: service(), + + async model() { + performance.mark('start-data-generation'); + + const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json()); + const updatePayload = await fetch('./fixtures/add-children-final.json').then((r) => r.json()); + + performance.mark('start-push-initial-payload'); + this.store.push(initialPayload); + + performance.mark('start-initial-materialize-records'); + let peekedParents = this.store.peekAll('parent').slice(); + this.store.peekAll('child').slice(); + + performance.mark('start-initial-materialize-relationships'); + let seen = new Set(); + peekedParents.forEach((parent) => iterateParent(parent, seen)); + + performance.mark('start-push-update-payload'); + this.store.push(updatePayload); + + performance.mark('start-materialize-all-records'); + peekedParents = this.store.peekAll('parent').slice(); + this.store.peekAll('child').slice(); + + performance.mark('start-materialize-all-relationships'); + seen = new Set(); + peekedParents.forEach((parent) => iterateParent(parent, seen)); + + performance.mark('end-materialize-all-relationships'); + }, +}); + +function iterateChild(record, seen) { + if (seen.has(record)) { + return; + } + seen.add(record); + // record.parent.get('name'); + record.bestFriend.get('name'); + record.secondBestFriend.get('name'); + record.friends.forEach((child) => iterateChild(child, seen)); +} +function iterateParent(record, seen) { + seen.add(record); + record.children.forEach((child) => iterateChild(child, seen)); +} diff --git a/packages/unpublished-relationship-performance-test-app/app/templates/application.hbs b/packages/unpublished-relationship-performance-test-app/app/templates/application.hbs index 3f1e58b858c..0d6ea09a371 100644 --- a/packages/unpublished-relationship-performance-test-app/app/templates/application.hbs +++ b/packages/unpublished-relationship-performance-test-app/app/templates/application.hbs @@ -7,5 +7,7 @@
  • Unload All
  • Destroy
  • Add Children
  • +
  • Add Children To Materialized
  • +
  • Add Children Then Materialize
  • Unused Relationships
  • \ No newline at end of file