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

Remove n^2 rendering problem with large symbol sets #235

Closed
wants to merge 5 commits into from

Conversation

ianhook
Copy link
Collaborator

@ianhook ianhook commented Dec 31, 2017

The original symbol code required injectSymbols to be called separately from makeSymbols because injectSymbols deletes the Symbols page and recreates it on every call. This can take a while as seen in #230.

I put the injectSymbols call in the render method, because this is the only time it needs to be called.

@alampros
Copy link

alampros commented Jan 4, 2018

Thanks, @ianhook – this is SOO much faster!

I've added a branch to test this on the demo repo that I created for #230: https://github.com/alampros/react-sketchapp-svg-render-test/tree/test-pull-235

@@ -6,54 +6,51 @@ import {
View,
Image,
makeSymbol,
injectSymbols,
Copy link

Choose a reason for hiding this comment

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

Can this be removed safely? It's throwing an eslint error.

@alampros
Copy link

alampros commented Jan 4, 2018

This error is thrown on render if makeSymbol is never called:

TypeError: null is not an object (evaluating 'Object.keys(mastersNameRegistry)')

It looks like adding this check (from makeSymbol) to injectSymbols fixes it:

  if (mastersNameRegistry === null) {
    getExistingSymbols();
  }

https://github.com/ianhook/react-sketchapp/blob/2a143bdf0a7c6649e35979d5c5fce976dc72a537/src/symbol.js#L75-L93

src/symbol.js Outdated
if (!notSymbolsPage) {
notSymbolsPage = globalContext.document.addBlankPage();
}
globalContext.document.setCurrentPage(notSymbolsPage);
Copy link
Collaborator

@mathieudutour mathieudutour Jan 8, 2018

Choose a reason for hiding this comment

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

shouldn't we store the current page at the beginning of the injectSymbols method and go back to it instead of getting the first one here?

@alampros
Copy link

What's involved in getting this merged and released?

@@ -28,6 +28,5 @@ module.exports = {
View,
Platform,
makeSymbol,
injectSymbols,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a breaking change. Could we maybe expose it again? (it's actually useful if you just want to generate the symbols without rendering anything as in #172 )

@mathieudutour
Copy link
Collaborator

merged as part of #254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants