Skip to content

[k2] crypto functions optimization - #1710

Open
LLirikkkk wants to merge 45 commits into
masterfrom
kkotliar/k2_crypto_functions_optimization
Open

LLirikkkk wants to merge 45 commits into
masterfrom
kkotliar/k2_crypto_functions_optimization

Conversation

@LLirikkkk

Copy link
Copy Markdown
Contributor

No description provided.

@LLirikkkk LLirikkkk added this to the next milestone Nov 5, 2026
@LLirikkkk LLirikkkk self-assigned this Nov 5, 2026
@LLirikkkk LLirikkkk added optimization Memory comsumption / CPU speedup runtime Feature related to runtime k2 Affects compiler or runtime in K2 mode labels Nov 5, 2026
Comment thread runtime-light/k2-platform/k2-header.h Resolved
Comment thread runtime-light/k2-platform/k2-api.h Resolved
Comment thread runtime-light/k2-platform/k2-api.h Resolved
Comment thread runtime-light/k2-platform/k2-header.h Resolved
Comment thread runtime-light/k2-platform/k2-header.h Resolved
}

return std::initializer_list<std::pair<string, mixed>>{{string{"name", 4}, string{name.value().data(), static_cast<string::size_type>(name.value().size())}},
{string{"subject", 7}, subject.val()},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to create these strings every time the function is called. We can create them in advance in CryptoImageState or OpenSSLImageState

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

std::pair{MD2, hash_algorithm_traits{MD2_HASHED_SIZE, HashAlgorithm::MD2}},
std::pair{MD4, hash_algorithm_traits{MD4_HASHED_SIZE, HashAlgorithm::MD4}}}};

std::ranges::sort(arr, std::less{}, &std::pair<std::string_view, hash_algorithm_traits>::first);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: std::addressof instead of raw & operator

@LLirikkkk LLirikkkk Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But in this case we take pointer to function, not object. We can not use std::addressof here.

return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}

inline constexpr char to_lower_ascii(char c) noexcept {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: tolower_ascii to look like std::tolower

const auto key{load_public_key(public_key)};
if (!key) [[unlikely]] {
kphp::log::warning("failed to verify signature");
return -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We must preserve kPHP's behavior: return 0

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 Affects compiler or runtime in K2 mode 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