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

THRIFT-4712: Improve Performance of ShortStack #1664

Merged
merged 1 commit into from Jan 3, 2019

Conversation

belugabehr
Copy link
Contributor

No description provided.

@jeking3
Copy link
Contributor

jeking3 commented Jan 1, 2019

Appreciate your changes. If you could also look at the backlog in Apache Jira and see if there are any existing issues you can tackle, that would also be appreciated.

@belugabehr
Copy link
Contributor Author

Sure thing. Thanks.

}

public void clear() {
top = -1;
top = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually clear? I don't think it does. It resets top to 0 and the next peek() will read whatever was there before. Shouldn't clear actually clear? If one peek()s after clear and there's nothing there, what should it do? Perhaps throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Well, the peek() method is not used anywhere other than the test framework, so it's a bit of a moot point; it should probably be removed altogether.

I think this is another example where the class should not be made public since it serves a very specific purpose. If it were scoped back into the package, it would have to be moved into the same package as the TCompactProtocol since that is what relies on this class. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

ShortStack was written in 2010. Perhaps it would be a good idea to analyze the performance of ShortStack managing 15 shorts vs. java.util.Stack in a more recent version of Java like 1.8. My guess is by now they've ironed out performance issues in containers like this... ideally we would try to remove ShortStack.java and its test all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JDK is still slow because of the auto-boxing of the primitive short value. In most cases, it wouldn't make a difference, but for a serialization library that needs to be as fast as possible, it's measurable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have evidence of this or is it just theory?

Copy link
Contributor Author

@belugabehr belugabehr Jan 3, 2019

Choose a reason for hiding this comment

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

Ya, I benchmarked it. I did two different scenarios. I didn't even bother including the Java JDK Stack implementation in the more aggressive scenario because it wasn't even close in the more trivial test.

https://issues.apache.org/jira/browse/THRIFT-4712?focusedCommentId=16731695&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16731695

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

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

Not sure clear() actually clear()s.

@belugabehr
Copy link
Contributor Author

The clear() method does the job. It sets the pointed back to the first open slot so that it can be overwritten. This is much faster than clearing the entire buffer or allocating a new one, and for these purposes, works well, now that I also removed the peek() method.

@jeking3 jeking3 merged commit 88584f8 into apache:master Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants