Skip to content

Lift memoization out of core - #678

Merged
ocrickard merged 2 commits into
facebook:masterfrom
ocrickard:memoization-again
Dec 8, 2016
Merged

Lift memoization out of core#678
ocrickard merged 2 commits into
facebook:masterfrom
ocrickard:memoization-again

Conversation

@ocrickard

Copy link
Copy Markdown
Contributor

My goal here is to reduce the need for customizations to the build and layout calls in every rendering context that wants memoization. Here's an example of what I'm trying to avoid:

#675

If your component hierarchy needs memoization, it should work regardless of how you configure your components, and ideally we wouldn't have to do this type of change to every place that builds components.

In this diff I introduce CKMemoizingComponent which prepares the thread-local state for component and layout memoization for its children. This component stores its memoization state into its scope's state.

Due to the nature of the thread-local stack that memoizers are built with, it should be fine to have multiple memoization components in the hierarchy with little cost, and everything "just works". This is important, since if you embed a sub-hierarchy that adds one of these so it can memoize in a different context, you don't want it to conflict with a higher-level memoizing component wrapper.

I'd like to land this first, then look at fixing up the scopes/states as in #348 after this is in master. Looking at that diff, we can apply basically the same process here.

@ocrickard

Copy link
Copy Markdown
Contributor Author

@facebook-github-bot import

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard updated the pull request - view changes - changes since last import

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard updated the pull request - view changes - changes since last import

@ocrickard

Copy link
Copy Markdown
Contributor Author

@darknoon feel free to take a look!

@conradev

Copy link
Copy Markdown

This looks great! Good to see it being moved out of the core.

@eczarny eczarny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ocrickard I think this is a great change! I think this is largely fine as-is but it would be nice to better consolidate the public-facing aspects of the memoization API.

Comment thread ComponentKit/Core/CKComponentMemoizer.h Outdated
restrictedToSize:size
relativeToParentSize:parentSize];
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a good idea to add these comments to the CKMemoizeLayout function itself.

How much of this header is actually part of the public-facing API? I ask because there is a fair amount of stuff here and we should take this opportunity to clean this up a bit if we want to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'd like to handle hiding this stuff later. There are a few functions we can move out-of-line, but most of it has to be public.

CKComponentLayout CKMemoizeOrComputeLayout(CKComponent *component, CKSizeRange constrainedSize, const CKComponentSize& size, CGSize parentSize)
CKComponentLayout CKMemoizeLayout(CKComponent *component, CKSizeRange constrainedSize, const CKComponentSize& size, CGSize parentSize, CKComponentLayout (^block)())
{
if (component && [component shouldMemoizeLayout]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks if the component is non-nil. Is that something we still need to guarantee?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add it back. I don't think it matters though. Pretty sure we're nil-safe here.

@eczarny

eczarny commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

@ocrickard back to you for my feedback and resolving merge conflicts.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard updated the pull request - view changes - changes since last import

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard updated the pull request - view changes - changes since last import

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ocrickard updated the pull request - view changes - changes since last import

@ocrickard

Copy link
Copy Markdown
Contributor Author

@facebook-github-bot import

@ocrickard

Copy link
Copy Markdown
Contributor Author

Alright, this is landing internally. Travis seems super backed up, but I'll wait for a green build here before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants