Skip to content

cleanup(libsinsp): untangle table/entry class hierarchy#2848

Merged
poiana merged 11 commits intofalcosecurity:masterfrom
gnosek:table-cleanup-extensible-table
Mar 16, 2026
Merged

cleanup(libsinsp): untangle table/entry class hierarchy#2848
poiana merged 11 commits intofalcosecurity:masterfrom
gnosek:table-cleanup-extensible-table

Conversation

@gnosek
Copy link
Contributor

@gnosek gnosek commented Feb 19, 2026

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind test

/kind feature

/kind sync

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-modern-bpf

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

This PR makes the following changes to the class hierarchy involved in tables/entries:

  • table_entry is now a base class that imposes no constraints on the implementation (doesn't force static/dynamic fields) -- no longer inherits from extensible_struct
  • built_in_table no longer requires static/dynamic fields in its entries -- this is moved to extensible_table.

So, if you want to build a "normal" table, with static and dynamic fields, inherit from extensible_table and extensible_struct. Otherwise (STL table adapters have neither static nor dynamic fields in the "can use the implementation" sense), inherit from built_in_table and table_entry directly and implement everything yourself.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

This is a fairly large one, so it probably works best commit by commit.

Does this PR introduce a user-facing change?:

NONE

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Perf diff from master - unit tests

    10.08%    +10.39%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    14.22%     -6.55%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     9.58%     -3.04%  [.] sinsp_threadinfo::update_main_fdtable()
     7.92%     +2.95%  [.] sinsp_threadinfo::get_fd_table()
    15.86%     -2.32%  [.] std::__shared_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     4.27%     +0.87%  [.] thread_group_info::get_first_thread() const
     9.82%     -0.64%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
    11.65%     +0.36%  [.] sinsp_threadinfo::get_main_thread()
     0.24%     -0.17%  [.] void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag)
     3.92%     +0.17%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)

Heap diff from master - unit tests

peak heap memory consumption: 13.28M
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 334.66K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            -0.0423         -0.0422           246           235           246           235
BM_sinsp_split_median                                          -0.0413         -0.0412           246           235           245           235
BM_sinsp_split_stddev                                          -0.6281         -0.6339             5             2             5             2
BM_sinsp_split_cv                                              -0.6117         -0.6177             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  -0.0148         -0.0147            69            68            69            68
BM_sinsp_concatenate_paths_relative_path_median                -0.0009         -0.0008            68            68            68            68
BM_sinsp_concatenate_paths_relative_path_stddev                -0.7892         -0.7909             1             0             1             0
BM_sinsp_concatenate_paths_relative_path_cv                    -0.7860         -0.7877             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0177         -0.0177            42            42            42            42
BM_sinsp_concatenate_paths_empty_path_median                   -0.0172         -0.0170            42            42            42            42
BM_sinsp_concatenate_paths_empty_path_stddev                   -0.7096         -0.7007             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       -0.7044         -0.6954             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.0061         +0.0062            69            70            69            70
BM_sinsp_concatenate_paths_absolute_path_median                +0.0158         +0.0159            69            70            69            70
BM_sinsp_concatenate_paths_absolute_path_stddev                -0.4723         -0.4730             1             1             1             1
BM_sinsp_concatenate_paths_absolute_path_cv                    -0.4756         -0.4763             0             0             0             0

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 71.80851% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.31%. Comparing base (30a8910) to head (5dba7bc).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/state/table_adapters.h 60.97% 32 Missing ⚠️
userspace/libsinsp/state/table.cpp 48.57% 18 Missing ⚠️
userspace/libsinsp/state/table.h 88.23% 2 Missing ⚠️
userspace/libsinsp/test/state.ut.cpp 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2848      +/-   ##
==========================================
- Coverage   75.38%   75.31%   -0.08%     
==========================================
  Files         295      295              
  Lines       31306    31304       -2     
  Branches     4898     4925      +27     
==========================================
- Hits        23601    23576      -25     
- Misses       7705     7728      +23     
Flag Coverage Δ
libsinsp 75.31% <71.80%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ekoops ekoops added this to the 0.24.0 milestone Feb 24, 2026
ekoops
ekoops previously approved these changes Feb 24, 2026
Copy link
Contributor

@ekoops ekoops 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 Feb 24, 2026

LGTM label has been added.

DetailsGit tree hash: 219c0ebf0ef2eb954245193cd18b2508d1a4430d

Copy link
Contributor

@irozzo-1A irozzo-1A left a comment

Choose a reason for hiding this comment

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

Just a few clarification requests

"invalid field info passed to pair_table_entry_adapter::write_field");
protected:
[[nodiscard]] const void* raw_read_field(const accessor& a) const override {
auto acc = dynamic_cast<const stl_table_raw_accessor*>(&a);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a nullptr check here to be more defensive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a dynamic_cast only to shut up clang-tidy (this cast goes away eventually). A dynamic_cast won't work if the accessor happens to be from a table that's not from libs core (any plugin-provided table). So the only safety we get from this is against using a threadinfo field with a fdinfo and vice versa. I don't think this buys us anything for the overhead (dynamic_casts are slow) and I won't miss it when it's gone.

ASAN helps with this a little.

@gnosek gnosek force-pushed the table-cleanup-extensible-table branch from df73200 to 1f31570 Compare March 4, 2026 16:26
@poiana poiana removed the lgtm label Mar 4, 2026
@poiana poiana requested a review from ekoops March 4, 2026 16:26
Copy link
Contributor

@irozzo-1A irozzo-1A left a comment

Choose a reason for hiding this comment

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

I'm good with the rest of the comments, I just spot a potential UB see my comment below.

Comment on lines +367 to +369
inline extensible_table(const std::string& name):
built_in_table<KeyType>(name),
m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to initialize m_static_fields to avoid UB

Suggested change
inline extensible_table(const std::string& name):
built_in_table<KeyType>(name),
m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {}
inline extensible_table(const std::string& name):
built_in_table<KeyType>(name),
m_static_fields(nullptr),
m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {}

gnosek added 6 commits March 16, 2026 13:28
…ible_struct

The old versions of the code are left only to make the patch readable.
The next commit removes them.

Signed-off-by: Grzegorz Nosek <[email protected]>
gnosek added 5 commits March 16, 2026 13:28
Note: this does cause uninitialized memory access when calling
static_fields() on a table that doesn't have any, so Don't Do That
for now. We'll fix it by removing static_fields() soon.

Signed-off-by: Grzegorz Nosek <[email protected]>
You should not need to access these on an instance any more (just call
->get_field instead).

Signed-off-by: Grzegorz Nosek <[email protected]>
This is no longer a part of the public API.

Signed-off-by: Grzegorz Nosek <[email protected]>
@gnosek gnosek force-pushed the table-cleanup-extensible-table branch from 1f31570 to 5dba7bc Compare March 16, 2026 12:29
@irozzo-1A irozzo-1A self-requested a review March 16, 2026 13:21
Copy link
Contributor

@irozzo-1A irozzo-1A left a comment

Choose a reason for hiding this comment

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

/lgtm

@poiana
Copy link
Contributor

poiana commented Mar 16, 2026

LGTM label has been added.

DetailsGit tree hash: 0a36c006f9d19889c69bff2975d98dce4564ad99

@github-project-automation github-project-automation bot moved this from Todo to In progress in Falco Roadmap Mar 16, 2026
@poiana
Copy link
Contributor

poiana commented Mar 16, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, gnosek, irozzo-1A

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [ekoops,gnosek,irozzo-1A]

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 f790124 into falcosecurity:master Mar 16, 2026
45 of 46 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Falco Roadmap Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants