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
use allocation free converstion from byte slice to string #116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: updated based on 23fbe24
% benchstat before.txt after.txt
name old time/op new time/op delta
pkg:github.com/elastic/go-libaudit/v2/aucoalesce goos:darwin goarch:amd64
CoalesceMessages-10 3.11µs ± 0% 3.24µs ± 0% ~ (p=1.000 n=1+1)
pkg:github.com/elastic/go-libaudit/v2/auparse goos:darwin goarch:amd64
ExtractKeyValuePairs/bpf_message-10 7.81µs ± 0% 7.85µs ± 0% ~ (p=1.000 n=1+1)
ExtractKeyValuePairs/short_message-10 1.27µs ± 0% 1.28µs ± 0% ~ (p=1.000 n=1+1)
AuditMessageData/syscall-10 21.9µs ± 0% 21.6µs ± 0% ~ (p=1.000 n=1+1)
AuditMessageData/user_cmd-10 14.9µs ± 0% 15.0µs ± 0% ~ (p=1.000 n=1+1)
ParseAuditHeader-10 147ns ± 0% 98ns ± 0% ~ (p=1.000 n=1+1)
ParseAuditHeaderRegex-10 545ns ± 0% 551ns ± 0% ~ (p=1.000 n=1+1)
ParseLogLine-10 360ns ± 0% 230ns ± 0% ~ (p=1.000 n=1+1)
name old alloc/op new alloc/op delta
pkg:github.com/elastic/go-libaudit/v2/aucoalesce goos:darwin goarch:amd64
CoalesceMessages-10 2.72kB ± 0% 2.72kB ± 0% ~ (all equal)
pkg:github.com/elastic/go-libaudit/v2/auparse goos:darwin goarch:amd64
ExtractKeyValuePairs/bpf_message-10 3.08kB ± 0% 3.08kB ± 0% ~ (all equal)
ExtractKeyValuePairs/short_message-10 1.00kB ± 0% 1.00kB ± 0% ~ (p=1.000 n=1+1)
AuditMessageData/syscall-10 15.3kB ± 0% 15.3kB ± 0% ~ (p=1.000 n=1+1)
AuditMessageData/user_cmd-10 3.68kB ± 0% 3.68kB ± 0% ~ (p=1.000 n=1+1)
ParseAuditHeader-10 21.0B ± 0% 0.0B ~ (p=1.000 n=1+1)
ParseAuditHeaderRegex-10 128B ± 0% 128B ± 0% ~ (all equal)
ParseLogLine-10 358B ± 0% 112B ± 0% ~ (p=1.000 n=1+1)
name old allocs/op new allocs/op delta
pkg:github.com/elastic/go-libaudit/v2/aucoalesce goos:darwin goarch:amd64
CoalesceMessages-10 13.0 ± 0% 13.0 ± 0% ~ (all equal)
pkg:github.com/elastic/go-libaudit/v2/auparse goos:darwin goarch:amd64
ExtractKeyValuePairs/bpf_message-10 44.0 ± 0% 44.0 ± 0% ~ (all equal)
ExtractKeyValuePairs/short_message-10 11.0 ± 0% 11.0 ± 0% ~ (all equal)
AuditMessageData/syscall-10 130 ± 0% 130 ± 0% ~ (all equal)
AuditMessageData/user_cmd-10 64.0 ± 0% 64.0 ± 0% ~ (all equal)
ParseAuditHeader-10 3.00 ± 0% 0.00 ~ (p=1.000 n=1+1)
ParseAuditHeaderRegex-10 2.00 ± 0% 2.00 ± 0% ~ (all equal)
ParseLogLine-10 4.00 ± 0% 1.00 ± 0% ~ (p=1.000 n=1+1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really have a regression test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that the only place where the unsafe conversion is actually needed is in auparse/hex.go and it could be a local function in that file.
friendly ping @andrewkroh && @efd6 |
After a test is added for the new function I am OK with this. It doesn't need to be much, just that the unsafe string of []byte of x is x. |
Added tests for |
Signed-off-by: Florian Lehner <florian.lehner@elastic.co> Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
friendly ping @andrewkroh && @efd6 I don't have the permissions to merge something. Therefore, please advice on who to continue. |
friendly ping @andrewkroh && @efd6 && @adriansr I don't have the permissions to merge something. Therefore, please advice on who to continue. |
Reduce allocations when converting bytes to strings for received messages. [elastic#116](elastic/go-libaudit#116)
Thanks 🙏 |
Reduce allocations when converting bytes to strings for received messages. [#116](elastic/go-libaudit#116) (cherry picked from commit 7a469fd)
Reduce allocations when converting bytes to strings for received messages. [elastic#116](elastic/go-libaudit#116)
Reassembler.Push has always made a copy of the provided byte slice. It elastic#116 it was modified to not copy the slice. But this was a breaking change to its behavior and causes bugs for existing users. The typical use of this function is to parse data from AuditClient.Receive which explicitly documents that caller must make a copy of the data if they are going to retain it beyond the next Receive call. Relates elastic#116
Reassembler.Push has always made a copy of the provided byte slice. It #116 it was modified to not copy the slice. But this was a breaking change to its behavior and causes bugs for existing users. The typical use of this function is to parse data from AuditClient.Receive which explicitly documents that caller must make a copy of the data if they are going to retain it beyond the next Receive call. Relates #116
Reduce allocations when converting bytes to strings for received messages. [#116](elastic/go-libaudit#116)
Signed-off-by: Florian Lehner florian.lehner@elastic.co
Reduce the number of allocations for converting a slice of bytes to a string.
Less allocation results in less work for GC.