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

fix(userspace/libsinsp): assorted pass-by-reference performance optimizations #1965

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind cleanup

Any specific area of the project related to this PR?

/area libsinsp

Does this PR require a change in the driver versions?

What this PR does / why we need it:

When looking at performance profiles of Falco, I discovered that we unwillingly pass variables by value more than needed. Specially with shared pointers, we occasionally prevent compilers from inlining and eliding reference counting that causes a non-negligible cost when running on high event throughput. At the same time, we use shared pointers even when not needed on internal functions.

Which issue(s) this PR fixes:

Special notes for your reviewer:

/milestone 0.18.0

Does this PR introduce a user-facing change?:

fix(userspace/libsinsp): assorted pass-by-reference performance optimizations

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link

Perf diff from master - unit tests

     6.71%     +2.00%  [.] sinsp::next
     5.12%     -1.91%  [.] sinsp_thread_manager::find_thread
     2.68%     +1.62%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release
    10.30%     +1.33%  [.] sinsp_parser::reset
     4.11%     -1.10%  [.] sinsp_thread_manager::get_thread_ref
     4.12%     -0.86%  [.] sinsp_evt::load_params
     5.48%     -0.81%  [.] next
     3.43%     +0.76%  [.] gzfile_read
     1.43%     -0.67%  [.] sinsp_parser::event_cleanup
     1.11%     -0.53%  [.] std::vector<sinsp_evt_param, std::allocator<sinsp_evt_param> >::emplace_back<sinsp_evt*, unsigned int&, char const*, unsigned long&>

Perf diff from master - scap file

     9.70%     -4.59%  [.] 0x00000000000a77e0
    10.12%     -3.15%  [.] sinsp_filter_check_thread::extract_single
     2.53%     +1.82%  [.] sinsp_filter_check_event::extract_single
     2.48%     +1.81%  [.] sinsp_thread_manager::get_thread_ref
     2.57%     +1.75%  [.] sinsp::next
     5.04%     +1.67%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>
     7.57%     -1.58%  [.] sinsp_filter_check::get_field_info
     7.57%     -1.49%  [.] sinsp_filter_check::extract_nocache
     4.97%     -1.49%  [.] sinsp_filter_check::get_transformed_field_info
     4.96%     -1.48%  [.] sinsp_filter_check::apply_transformers

Heap diff from master - unit tests

total runtime: 0.13s.
calls to allocation functions: 9031 (70554/s)
temporary memory allocations: -10141 (-79226/s)
peak heap memory consumption: -160.08K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

total runtime: -0.02s.
calls to allocation functions: -3 (176/s)
temporary memory allocations: -9 (529/s)
peak heap memory consumption: -4.10K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

Thank you!

@poiana
Copy link
Contributor

poiana commented Jul 19, 2024

LGTM label has been added.

Git tree hash: e3cb6c12b70478f8ccb682ce4af0141be9fd4f94

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jul 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, jasondellaluce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit ae6b268 into master Jul 19, 2024
41 of 43 checks passed
@poiana poiana deleted the fix/allocations-shared-ptr branch July 19, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants