Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.1 cache #8122

Merged
merged 28 commits into from
Aug 17, 2022
Merged

v2.1 cache #8122

merged 28 commits into from
Aug 17, 2022

Conversation

runspired
Copy link
Contributor

@runspired runspired commented Aug 13, 2022

Performance (and size) will get worse before they get better for this feature. Since we have to wrap every single RecordData in a unique manager so long as V1 exists, I would expect this to initially negate a significant portion of the (sizeable) improvements from the simplification work and removal of InternalModel.

However!

Since the fully v2 cache world is capable of being a singleton (and our implementation will be so), once v1 is not in the system we drop from 2N classes to support N records in the cache to two class instances (total). It is at that point I would expect to see us regain double what we lost from adding in the manager.

My hope is that we can produce a mechanism such that an app may signal that V1 is not in use, which our standard build infra will then make use of to remove the expensive codepath and utilize the cheap one. Ideally this will all be in place prior to merging this PR.

Release Notes

  • Implements NonSingleton Manager
  • Implements Cache v2
  • Implements Singleton Manager
  • Documents the Manager
  • Implements Production Manager Mode
  • Activates Singleton Cache (but not Singleton manager)

The singleton cache and singleton manager are currently both behind feature flags, only singleton cache is activated (since this is our own implementation this is easier for us to achieve with some safety).

A follow up PR to this one will activate singleton manager as well as document the v2 cache format and deprecate the v1 cache format.

While studying the cost centers of the various benchmarks I came away with the following observations (once singleton-manager is activated)

  • our biggest cost centers are down to three things:
  1. instantiating things which extend Model
  2. populating the graph
  3. updating the live RecordArray (specifically updates, not full clears / add from empty)

(1) and (3) are respectively cost centers that will be significantly improved as we see through the plan for 5.0, as eliminating EmberObject / ArrayProxy from the equation will simplify this significantly.

(2) requires rebooting and finishing #7521 with the additional observation that we should eliminate the classes used to hold state for each edge as they are largely dumb containers at this point.

@runspired runspired added 🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166 🎯 canary PR is targeting canary (default) 🏷️ feat This PR introduces a new feature 🏷️ doc This PR adds/improves/or fixes documentation 🏷️ deprecation 5.0 Roadmap labels Aug 13, 2022
@runspired runspired added this to In Development in 🌲 Project Trim 🌲 via automation Aug 13, 2022
@runspired
Copy link
Contributor Author

this PR replaces #5931

@github-actions
Copy link

github-actions bot commented Aug 13, 2022

Asset Size Report for 36340c8

Modern Builds

🛑 The size of the library EmberData has increased by +3.34 KB (+551.0 B compressed) which exceeds the failure threshold of 75 bytes.

Warnings

⚠️ The uncompressed size of the package @ember-data/store has increased by +4.46 KB.

Changeset


EmberData +170.15 KB +3.34 KB (+35.48 KB +551.0 B compressed)
    @ember-data/model +45.34 KB -434.0 B (+9.46 KB -69.94 B compressed)
        @ember-data/model/-private +44.87 KB -434.0 B (+9.36 KB -69.94 B compressed)
    @ember-data/store +46.89 KB +4.46 KB (+9.78 KB +735.53 B compressed)
        @ember-data/store/-private +45.89 KB +4.46 KB (+9.57 KB +735.53 B compressed)
    @ember-data/record-data +23.48 KB -711.0 B (+4.9 KB -114.58 B compressed)
        @ember-data/record-data/-private +23.48 KB -711.0 B (+4.9 KB -114.58 B compressed)

Full Asset Analysis (Modern)

Asset Size Report
=================


Library: EmberData
┌────────────┬─────────────┐
│  (index)   │   Values    │
├────────────┼─────────────┤
│   bytes    │ '170.15 KB' │
│ compressed │ '35.48 KB'  │
│  packages  │      8      │
│  modules   │     44      │
└────────────┴─────────────┘

Package: @ember-data/store
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '46.89 KB' │
│  compressed  │ '9.78 KB'  │
│ % Of Library │   '27.6'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/store/-private                        | 45.89 KB  | 9.57 KB    | 97.9          | 27.0
	@ember-data/store/index                           | 1022.00 B | 213.13 B   | 2.1           | 0.6

Package: @ember-data/model
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '45.34 KB' │
│  compressed  │ '9.46 KB'  │
│ % Of Library │   '26.6'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/model/-private                        | 44.87 KB  | 9.36 KB    | 99.0          | 26.4
	@ember-data/model/index                           | 486.00 B  | 101.35 B   | 1.0           | 0.3

Package: @ember-data/record-data
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '23.48 KB' │
│  compressed  │ '4.90 KB'  │
│ % Of Library │   '13.8'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/record-data/-private                  | 23.48 KB  | 4.90 KB    | 100.0         | 13.8

Package: @ember-data/serializer
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '20.42 KB' │
│  compressed  │ '4.26 KB'  │
│ % Of Library │   '12.0'   │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/serializer/json                       | 7.36 KB   | 1.53 KB    | 36.0          | 4.3
	@ember-data/serializer/-private                   | 5.60 KB   | 1.17 KB    | 27.4          | 3.3
	@ember-data/serializer/json-api                   | 3.79 KB   | 809.35 B   | 18.6          | 2.2
	@ember-data/serializer/rest                       | 2.87 KB   | 611.86 B   | 14.0          | 1.7
	@ember-data/serializer/index                      | 611.00 B  | 127.41 B   | 2.9           | 0.4
	@ember-data/serializer/transform                  | 215.00 B  | 44.83 B    | 1.0           | 0.1

Package: @ember-data/adapter
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '15.93 KB' │
│  compressed  │ '3.32 KB'  │
│ % Of Library │   '9.4'    │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/adapter/rest                          | 7.88 KB   | 1.64 KB    | 49.5          | 4.6
	@ember-data/adapter/-private                      | 3.79 KB   | 808.31 B   | 23.8          | 2.2
	@ember-data/adapter/error                         | 1.82 KB   | 389.14 B   | 11.4          | 1.1
	@ember-data/adapter/index                         | 1.41 KB   | 301.55 B   | 8.9           | 0.8
	@ember-data/adapter/json-api                      | 1.03 KB   | 220.84 B   | 6.5           | 0.6

Package: ember-data
┌──────────────┬───────────┐
│   (index)    │  Values   │
├──────────────┼───────────┤
│    bytes     │ '8.66 KB' │
│  compressed  │ '1.81 KB' │
│ % Of Library │   '5.1'   │
└──────────────┴───────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	ember-data/index                                  | 2.11 KB   | 450.24 B   | 24.4          | 1.2
	ember-data/-private                               | 1.75 KB   | 373.08 B   | 20.2          | 1.0
	ember-data/adapters/errors                        | 1.19 KB   | 253.79 B   | 13.7          | 0.7
	ember-data/setup-container                        | 368.00 B  | 76.74 B    | 4.2           | 0.2
	ember-data/relationships                          | 318.00 B  | 66.31 B    | 3.6           | 0.2
	ember-data/serializers/embedded-records-mixin     | 274.00 B  | 57.14 B    | 3.1           | 0.2
	ember-data/serializers/json-api                   | 251.00 B  | 52.34 B    | 2.8           | 0.1
	ember-data/adapters/json-api                      | 245.00 B  | 51.09 B    | 2.8           | 0.1
	ember-data/serializers/json                       | 243.00 B  | 50.67 B    | 2.7           | 0.1
	ember-data/serializers/rest                       | 243.00 B  | 50.67 B    | 2.7           | 0.1
	ember-data/transform                              | 241.00 B  | 50.25 B    | 2.7           | 0.1
	ember-data/adapters/rest                          | 237.00 B  | 49.42 B    | 2.7           | 0.1
	ember-data/serializer                             | 232.00 B  | 48.38 B    | 2.6           | 0.1
	ember-data/adapter                                | 226.00 B  | 47.13 B    | 2.5           | 0.1
	ember-data/model                                  | 222.00 B  | 46.29 B    | 2.5           | 0.1
	ember-data/store                                  | 222.00 B  | 46.29 B    | 2.5           | 0.1
	ember-data/attr                                   | 218.00 B  | 45.46 B    | 2.5           | 0.1
	ember-data/version                                | 161.00 B  | 33.57 B    | 1.8           | 0.1

Package: ember-inflector
┌──────────────┬───────────┐
│   (index)    │  Values   │
├──────────────┼───────────┤
│    bytes     │ '6.67 KB' │
│  compressed  │ '1.39 KB' │
│ % Of Library │   '3.9'   │
└──────────────┴───────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	ember-inflector/lib/system/inflector              | 2.96 KB   | 632.71 B   | 44.4          | 1.7
	ember-inflector/lib/system/inflections            | 1.59 KB   | 339.29 B   | 23.8          | 0.9
	ember-inflector/lib/system                        | 471.00 B  | 98.22 B    | 6.9           | 0.3
	ember-inflector/index                             | 379.00 B  | 79.03 B    | 5.6           | 0.2
	ember-inflector/lib/helpers/pluralize             | 369.00 B  | 76.95 B    | 5.4           | 0.2
	ember-inflector/lib/utils/make-helper             | 332.00 B  | 69.23 B    | 4.9           | 0.2
	ember-inflector/lib/system/string                 | 318.00 B  | 66.31 B    | 4.7           | 0.2
	ember-inflector/lib/helpers/singularize           | 296.00 B  | 61.72 B    | 4.3           | 0.2

Package: @ember-data/debug
┌──────────────┬────────────┐
│   (index)    │   Values   │
├──────────────┼────────────┤
│    bytes     │ '2.77 KB'  │
│  compressed  │ '590.80 B' │
│ % Of Library │   '1.6'    │
└──────────────┴────────────┘
	Module                                            | Bytes     | Compressed | % of Package  | % Of Library
	-----------------------------------------------------------------------------------------------------
	@ember-data/debug/index                           | 2.27 KB   | 485.48 B   | 82.2          | 1.3
	@ember-data/debug/setup                           | 505.00 B  | 105.31 B   | 17.8          | 0.3

Modern Builds (No Rollup)

☑️ EmberData has not changed in size

If any packages had changed sizes they would be listed here.

Changeset



Full Asset Analysis (Modern)

Asset Size Report
=================


Library: EmberData
┌────────────┬──────────┐
│  (index)   │  Values  │
├────────────┼──────────┤
│   bytes    │ '0.00 B' │
│ compressed │ '1.00 B' │
│  packages  │    0     │
│  modules   │    0     │
└────────────┴──────────┘

@github-actions
Copy link

github-actions bot commented Aug 13, 2022

Performance Report for 36340c8

Scenario - basic-record-materialization: ☑️ Performance is stable

☑️ duration
phase no difference [-64ms to 98ms]
☑️ Phase [navigationStart] => [start-data-generation]
phase no difference [-7ms to 9ms]
☑️ Phase [start-data-generation] => [start-push-payload]
phase no difference [-14ms to 1ms]
⚠️ Phase [start-push-payload] => [start-peek-records]
phase estimated regression +53ms [7ms to 98ms] OR +1.94% [0.26% to 3.56%]
⚠️ Phase [start-peek-records] => [start-record-materialization]
phase estimated regression +17ms [14ms to 21ms] OR +21.83% [17.44% to 26.1%]
☑️ Phase [start-record-materialization] => [end-record-materialization]
phase no difference [-82ms to 94ms]
☑️ Phase [end-record-materialization] => [Test End]
phase no difference [-1ms to 32ms]

Scenario - relationship-materialization-simple: ⚠️ Performance regressed

⚠️ duration
phase estimated regression +41ms [17ms to 64ms] OR +3.11% [1.34% to 4.89%]
☑️ Phase [navigationStart] => [start-find-all]
phase no difference [-8ms to 10ms]
⚠️ Phase [start-find-all] => [start-materialization]
phase estimated regression +15ms [6ms to 24ms] OR +2.84% [1.09% to 4.61%]
☑️ Phase [start-materialization] => [end-materialization]
phase no difference [-5ms to 12ms]
⚠️ Phase [end-materialization] => [Test End]
phase estimated regression +3ms [2ms to 5ms] OR +8.44% [5.19% to 14.46%]

Scenario - relationship-materialization-complex: ☑️ Performance is stable

☑️ duration
phase no difference [-3ms to 145ms]
☑️ Phase [navigationStart] => [start-data-generation]
phase no difference [-8ms to 8ms]
☑️ Phase [start-data-generation] => [start-push-payload]
phase no difference [-2ms to 5ms]
⚠️ Phase [start-push-payload] => [start-peek-records]
phase estimated regression +21ms [1ms to 42ms] OR +1.57% [0.1% to 3.12%]
⚠️ Phase [start-peek-records] => [start-record-materialization]
phase estimated regression +13ms [11ms to 15ms] OR +40.68% [35.42% to 46.6%]
✅ Phase [start-record-materialization] => [start-relationship-materialization]
phase estimated improvement -27ms [-39ms to -16ms] OR -4.47% [-6.46% to -2.7%]
☑️ Phase [start-relationship-materialization] => [end-relationship-materialization]
phase no difference [-1ms to 104ms]
☑️ Phase [end-relationship-materialization] => [Test End]
phase no difference [0ms to 17ms]

Scenario - unload: ☑️ Performance is stable

☑️ duration
phase no difference [-37ms to 13ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-11ms to 10ms]
☑️ Phase [start-push-payload] => [start-unload-records]
phase no difference [-12ms to 16ms]
✅ Phase [start-unload-records] => [end-unload-records]
phase estimated improvement -14ms [-20ms to -9ms] OR -5.09% [-7.03% to -3.39%]
⚠️ Phase [end-unload-records] => [Test End]
phase estimated regression +1ms [0ms to 2ms] OR +2.47% [0.58% to 4.33%]

Scenario - unload-all: ✅ Performance improved

✅ duration
phase estimated improvement -18060ms [-18217ms to -17878ms] OR -82.24% [-82.95% to -81.41%]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-4ms to 21ms]
☑️ Phase [start-push-payload] => [start-materialization]
phase no difference [-23ms to 51ms]
✅ Phase [start-materialization] => [start-unload-all]
phase estimated improvement -29ms [-48ms to -8ms] OR -3.45% [-5.78% to -0.97%]
✅ Phase [start-unload-all] => [end-unload-all]
phase estimated improvement -18053ms [-18180ms to -17927ms] OR -96.67% [-97.35% to -95.99%]
⚠️ Phase [end-unload-all] => [Test End]
phase estimated regression +1ms [1ms to 2ms] OR +3.48% [1.6% to 5.41%]

Scenario - destroy: ☑️ Performance is stable

☑️ duration
phase no difference [-26ms to 12ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-11ms to 8ms]
☑️ Phase [start-push-payload] => [start-destroy-records]
phase no difference [-5ms to 18ms]
✅ Phase [start-destroy-records] => [end-destroy-records]
phase estimated improvement -15ms [-18ms to -11ms] OR -6.2% [-7.57% to -4.65%]
⚠️ Phase [end-destroy-records] => [Test End]
phase estimated regression +2ms [1ms to 2ms] OR +4.37% [3.53% to 5.68%]

Scenario - add-children: ⚠️ Performance regressed

⚠️ duration
phase estimated regression +41ms [24ms to 58ms] OR +3.79% [2.25% to 5.37%]
☑️ Phase [navigationStart] => [start-push-initial-payload]
phase no difference [-5ms to 15ms]
⚠️ Phase [start-push-initial-payload] => [start-push-update-payload]
phase estimated regression +11ms [5ms to 17ms] OR +3.77% [1.86% to 5.89%]
⚠️ Phase [start-push-update-payload] => [end-push-update-payload]
phase estimated regression +15ms [11ms to 20ms] OR +6.4% [4.7% to 8.16%]
⚠️ Phase [end-push-update-payload] => [Test End]
phase estimated regression +11ms [10ms to 12ms] OR +20.4% [18.78% to 21.87%]

Scenario - unused-relationships: ☑️ Performance is stable

☑️ duration
phase no difference [-1ms to 33ms]
☑️ Phase [navigationStart] => [start-push-payload]
phase no difference [-4ms to 14ms]
☑️ Phase [start-push-payload] => [end-push-payload]
phase no difference [-9ms to 11ms]
⚠️ Phase [end-push-payload] => [Test End]
phase estimated regression +8ms [7ms to 10ms] OR +16.22% [14.34% to 19.47%]

@runspired runspired merged commit ddc9009 into master Aug 17, 2022
🌲 Project Trim 🌲 automation moved this from In Development to Completed Aug 17, 2022
@delete-merged-branch delete-merged-branch bot deleted the runspired/v2.1-cache branch August 17, 2022 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 Roadmap 🎯 canary PR is targeting canary (default) 🏷️ deprecation 🏷️ doc This PR adds/improves/or fixes documentation 🏷️ feat This PR introduces a new feature 🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant