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

JSONStack: Improve performance #3465

Merged
merged 2 commits into from
Aug 2, 2017

Conversation

obastemur
Copy link
Collaborator

1% Acme Air LTO gain. Majority of the time, there is at max 1 item on the stacks and SList too expensive to maintain 1item in/out during the whole JSON.stringify

@@ -37,22 +54,68 @@ namespace JSON
{
if (bJsObject)
{
return jsObjectStack.Push(data);
bool result = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactoring this into an inline function- something like PushObject(data, jsObjectStack, &STACK_VALUE)/PushObject(data, domObjectStack, &DOM_VALUE)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@digitalinfinity This also came to my mind. Good idea. However, all three functions may end up in similar inline function pairs. Current looked more cleaner (whole file is ~100 lines)

@@ -15,6 +15,7 @@ namespace JSON
class JSONStack
{
private:
Js::Var tempValues[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really your change, but more a question- are these references to Vars supposed to be kept alive? I see that this class uses an arena allocator so curious who keeps it alive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@digitalinfinity not sure about the answer. I added a destructor to make sure they are nullified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not a problem for JSONStack as it always cleans up the references once stringify is done with inner object/array etc.

@@ -24,10 +33,18 @@ namespace JSON
{
if (bJsObject)
{
if (STACK_VALUE)
{
return (data == STACK_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

return (data == STACK_VALUE); [](start = 16, length = 29)

just to guard future changes to this class, can you add assert at appropriate places to check when STACK_VALUE != nullptr, jsobjectStack is always empty and similarly for dom stack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kunalspathak not sure I understood. there is an if(STACK_VALUE) why should I check STACK_VALUE != nullptr inside an Assert?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant to say add assert something like

if(STACK_VALUE) 
{
  assert(jsObjectStack.Count() == 0);
   return (data == STACK_VALUE)
}

1% Acme Air LTO gain. Majority of the time, there is at max 1 item on
the stacks and SList is too expensive to maintain 1 item in/out during
the whole JSON.stringify
@obastemur
Copy link
Collaborator Author

@dotnet-bot test Ubuntu shared_ubuntu_linux_test please

@chakrabot chakrabot merged commit 2e19ab7 into chakra-core:release/1.7 Aug 2, 2017
chakrabot pushed a commit that referenced this pull request Aug 2, 2017
Merge pull request #3465 from obastemur:imp_jsonstack

1% Acme Air LTO gain. Majority of the time, there is at max 1 item on the stacks and SList too expensive to maintain 1item in/out during the whole JSON.stringify
@obastemur
Copy link
Collaborator Author

@digitalinfinity @kunalspathak Thanks for the review!

chakrabot pushed a commit that referenced this pull request Aug 2, 2017
Merge pull request #3465 from obastemur:imp_jsonstack

1% Acme Air LTO gain. Majority of the time, there is at max 1 item on the stacks and SList too expensive to maintain 1item in/out during the whole JSON.stringify
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.

5 participants