Skip to content

Properly assigning styles by deep copy #722

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

Merged
merged 2 commits into from
Apr 3, 2019
Merged

Conversation

Siemienik
Copy link
Member

  • var to const/let refactoring

+ var to const/let refactoring
@Siemienik Siemienik requested a review from guyonroche January 14, 2019 17:24
@Siemienik
Copy link
Member Author

#669

@@ -367,6 +367,6 @@ Row.prototype = {
this.hidden = value.hidden;
this.outlineLevel = value.outlineLevel || 0;

this.style = value.style || {};
this.style = value.style && JSON.parse(JSON.stringify(value.style)) || {};
Copy link
Member Author

Choose a reason for hiding this comment

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

fix is here ;)

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of this, since there's a couple of subtle ways this can fail or lose things depending on the shape of the object. do we know what values each key of value.style can hold? is it just a flat object of "some string": "another string" or can it also hold numbers, arrays, functions or other objects?

Copy link
Member Author

Choose a reason for hiding this comment

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

it is only object that keep configuration of styles
there aren't any functions or getters/setters

Copy link
Member

Choose a reason for hiding this comment

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

gotcha. Can you help me understand the performance impact here?
JSON.parse(JSON.stringify()) is quite slow and it would suck if this actually runs for all (or most) rows. Also, it increases the memory overhead a bit. How many rows will have this property?

Copy link
Member Author

Choose a reason for hiding this comment

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

personally I think it's much better to write style cloning function in utils ;)

Choose a reason for hiding this comment

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

Using JSON is indeed pretty slow to copy things. You could use e.g., https://github.com/davidmarkclements/rfdc for now (I would normally just recommend to use object spread but that's not available in versions below 8 and slow before v.10 or v.11 😄).

@alubbe the current API does not seem to have performance in mind. If the user changes any input that should be registered in a clean way so all internals can work side effect free. This does not seem to be possible without the penalty here. Using getters and setters might reduce the overhead by only copying values that have to be changed but as far as I see it that would probably be pretty brittle with the current code.

Copy link
Member

Choose a reason for hiding this comment

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

I agree - let's merge it and then actually benchmark why this library is slow and fix those, as opposed to pre-optimizing a bugfix

@alubbe
Copy link
Member

alubbe commented Jan 17, 2019

Let's do these refactorings as a separate PR - as a matter of fact, this is better done by an automated tool like prettier than by hand. Can you simplify this PR? I'll create a separate one for the ES6 refactoring.

@alubbe
Copy link
Member

alubbe commented Jan 17, 2019

@guyonroche any chance to get write access to merge PRs like this?

@Siemienik
Copy link
Member Author

@alubbe I really dislike do changes in all files in one time, it will make a lot of conflicts

@alubbe
Copy link
Member

alubbe commented Jan 18, 2019

on the contrary, doing it one file at a time makes for a really messy git log (making git blame useless) and introducing a highly inconsistent code basis. you are right with regards to the conflicts, so I suggest we merge what we can in the next 14 days - afterwards we merge the big style pr and I update every open PR by hand. how does that sound?

@@ -76,9 +76,9 @@ describe('WorkbookReader', function() {
});

describe('edit styles in existing file', function(){
beforeEach(async function(){
beforeEach(function(){
Copy link
Member

Choose a reason for hiding this comment

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

why? I quite like moving things to async/await. the test suite runs on node, so there's no transpiling here

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

damn, right you are :(

@alubbe
Copy link
Member

alubbe commented Feb 8, 2019

@Siemienik could you help understand if the object cloning is happening on the hot path for each row? how often do rows have this style property?

@Siemienik
Copy link
Member Author

Siemienik commented Feb 18, 2019

@alubbe as offen as style was set. in #669 is really well described example when it works wrong.

probably this solution isn't best of all, but it's best what i found. I am really open for any other propositions :)

@alubbe
Copy link
Member

alubbe commented Mar 12, 2019

Let's merge it then - I still don't have access to do it though :(

Copy link
Contributor

@defshift defshift left a comment

Choose a reason for hiding this comment

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

👍

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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy