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

do not initialize StringLibContext's static buffers #1229

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

apolyakov
Copy link
Contributor

@apolyakov apolyakov commented Jan 31, 2025

This pull request enhances the performance of the HelloWorld benchmark for K2 by a factor of 32. Previously, we used zero-initialized std::array as a buffer in StringLibContext. This zeroing of the 8MB array at the start of each request consumed significant CPU time. By switching to uninitialized std::array, we avoid unnecessary initialization, resulting in substantial performance improvements.

Following benchmark is enough to see the difference:

?php

echo "Hello, World!\n";

@apolyakov apolyakov added optimization Memory comsumption / CPU speedup runtime Feature related to runtime k2 k2 related labels Jan 31, 2025
@apolyakov apolyakov self-assigned this Jan 31, 2025
runtime-common/stdlib/string/string-context.h Outdated Show resolved Hide resolved
runtime-common/stdlib/string/string-context.h Outdated Show resolved Hide resolved
@apolyakov apolyakov force-pushed the apolyakov/k2-optimize-string-context branch from 19214f4 to c8f9c26 Compare January 31, 2025 14:49
@apolyakov apolyakov changed the title use std::aligned_storage instead of std::array as a buffer in StringLibContext do not initialize StringLibContext's static buffers Jan 31, 2025
@apolyakov apolyakov force-pushed the apolyakov/k2-optimize-string-context branch from 0891163 to 6b4fed3 Compare February 3, 2025 11:23
Copy link
Contributor

@mkornaukhov03 mkornaukhov03 left a comment

Choose a reason for hiding this comment

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

OK, but let's run better internal tests. I'll give an approve after passing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k2 k2 related optimization Memory comsumption / CPU speedup runtime Feature related to runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants