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

Optimize EOF by reading types on demand #1034

Merged

Conversation

elijahhampton
Copy link
Contributor

@elijahhampton elijahhampton commented Sep 27, 2024

Introduces EOF1Header::get_type function to read individual EOF
code types. This is fast procedure because we need to read at most 4
bytes and a know offset. By doing so we avoid allocating separated
vector to types.

Closes #1003.

@elijahhampton
Copy link
Contributor Author

This PR addresses: #1003

lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.hpp Outdated Show resolved Hide resolved
lib/evmone/eof.hpp Outdated Show resolved Hide resolved
lib/evmone/instructions.hpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
lib/evmone/eof.hpp Outdated Show resolved Hide resolved
lib/evmone/eof.hpp Show resolved Hide resolved
lib/evmone/eof.hpp Outdated Show resolved Hide resolved
lib/evmone/eof.cpp Outdated Show resolved Hide resolved
if (type_section_size != code_sizes.size() * 4)
return EOFValidationError::invalid_type_section_size;

auto validation_error = validate_types(container, type_section_offset, type_section_size);
Copy link
Member

Choose a reason for hiding this comment

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

This is quite an issue: validate_type() should not be used in validate_header() and invoke separately after validate_header(). This way we can just pass EOF1Header to validate_types() and use its .get_type() method.

But maybe this requires a separate PR. What do you think @gumb0?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to try in a separate PR.

It made sense to do it here before, becase "validate header" really meant "validate header and types and return them togethere in one struct"

@chfast chfast requested a review from gumb0 October 9, 2024 19:12
@@ -43,6 +61,11 @@ struct EOF1Header
/// The EOF version, 0 means legacy code.
uint8_t version = 0;

/// Size of every type section.
uint16_t type_section_size = 0;
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to store the size at all, because header validation guarantees that type_section_size == code_sizes.siz() * 4

@chfast chfast force-pushed the elijah/eof-dont-copy-type-section branch from 85d4bed to b8de2e6 Compare October 14, 2024 14:41
@chfast chfast changed the title Optimizes validate_types to read EOF types on demand. Optimize EOF by reading types on demand Oct 14, 2024
@chfast chfast force-pushed the elijah/eof-dont-copy-type-section branch 2 times, most recently from 09de4f8 to a54e9a5 Compare October 14, 2024 14:47
Introduces `EOF1Header::get_type` function to read individual EOF
code types. This is fast procedure because we need to read at most 4
bytes and a know offset. By doing so we avoid allocating separated
vector to types.
@chfast chfast force-pushed the elijah/eof-dont-copy-type-section branch from a54e9a5 to 21a78e3 Compare October 14, 2024 14:51
@chfast chfast enabled auto-merge (squash) October 14, 2024 14:58
@chfast chfast merged commit 589c1d6 into ethereum:master Oct 14, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EOF: Don't copy type section
3 participants