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

[optimization] - dynamically tracking of actual required size of each template to set optimal init-capacity of StringBuilder #21

Open
tunggad opened this issue Jun 17, 2011 · 2 comments

Comments

@tunggad
Copy link

tunggad commented Jun 17, 2011

Today i came across this blog http://kaioa.com/node/59, ther author was talking about the performance impact of setting init-capacity for StringBuilder. I quote here the important observation of the author:

"If you take a closer look you can also see that there is some kind of rhythm: the best initial capacities (local optimum) are always a power of two. And the worst results are always just before the next power of two. The perfect results are of course achieved if the required size is used from the very beginning (shown as dashed lines in the diagram) and no resizing happens at all."

And i come to the idea how we can optimize the performance of Japid abit futher. Now we hardcode init-capacity of StringBuilder in constructor of JapidTemplateBaseWithoutPlay. My idea is to have a global tracking mechanism of the actual required size of each template and after a warmup the JapidTemplateBaseWithoutPlay constructor will lookup the ideal init-capacity for each template here.

What do you think?

@branaway
Copy link
Owner

smart idea indeed. I had another idea before: each template class holds on to an instance of StringBuilder and each invocation of the same template reuses the same StringBuilder, so eventually the StringBuilder will have a capacity of the largest size it has ever served. There is no smart algorithm required. Of course I need have some mechanism to protect it from some extreme cases.

@tunggad
Copy link
Author

tunggad commented Jun 17, 2011

Oh your idea, i think is still smarter. Very importan, no need of such a automagical algorithm for dynamic tracking, simple to implement -> more stable. Ok, why do you still hesitate to implement it? ^^

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

No branches or pull requests

2 participants