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

Avoid memory copy when parsing log #202

Merged

Conversation

JackyWoo
Copy link
Contributor

Which issues of this PR fixes:

This PR try to fix #199

Change log:

  • Avoid memory copy when parsing log

@JackyWoo JackyWoo added enhancement Enhancements performance Performance promotion labels Feb 21, 2024
@JackyWoo JackyWoo added this to the Release v2.0.4 milestone Feb 21, 2024
@@ -572,7 +572,8 @@ int NuRaftLogSegment::loadLogEntry(int fd, off_t offset, LogEntryHeader * head,
return -1;
}

entry = LogEntryBody::parse(entry_str, head->term, head->data_length);
entry = LogEntryBody::parse(entry_str, head->data_length);
entry->set_term(head->term);

delete[] entry_str;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use buffer for entry_str instead of char pointer to avoid copy and delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because when we serialize data there is no header of buffer and this copy can not be avoided

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, maybe better to use buffer to avoid manual memory release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to worry about memory deallocation issues for the method is only invoked synchronously.

Copy link
Contributor Author

@JackyWoo JackyWoo Feb 27, 2024

Choose a reason for hiding this comment

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

But I think we should not use raw pointer in NuRaftLogSegment.cpp, maybe fixed in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay

@lzydmxy
Copy link
Contributor

lzydmxy commented Feb 27, 2024

LGTM

@JackyWoo JackyWoo merged commit 9e3043f into JDRaftKeeper:master Feb 27, 2024
6 checks passed
@nicelulu nicelulu removed the enhancement Enhancements label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance promotion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid useless memory copy when parsing log entry.
3 participants