Skip to content

(See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-major] to base-branch [main]. - #117

Merged
ygoldfeld merged 35 commits into
mainfrom
ipc-143_perf-dive-major
Nov 3, 2026
Merged

ygoldfeld merged 35 commits into
mainfrom
ipc-143_perf-dive-major

Conversation

@ygoldfeld

Copy link
Copy Markdown
Contributor

fixes #115, fixes #116
related to #82

  • flow.util: Add flow::util::stat sub-namespace: facilities for working with simple stat-holding structs ("stat-sets"). Each data member ("stat-member") is classified as an accumulator (counter), gauge, or high-water mark of a particular gauge.
    • Add Histogram_counter: usable as accumulator stat-member and standalone.
    • Stat-consuming API: direct-read stat-members from stat-sets; reset and pretty-print stat-sets; more.
    • Stat-collecting API: collect under concurrency (optionally with thread-local sharding) or single-threaded; or integrate with third-party stat sources.
  • flow.util: Add thread-local-related utilities to flow::util:
    • Thread_local_ptr<T> (fast boost::thread_specific_ptr<T> equivalent).
    • Thread_token, this_thread_unique_token() (actually-unique thread IDs).
    • Thread_local_obj_deinit_safe<T, Tag>.
  • flow.util: Add misc utilities: flow::util::Action_registry, Locked_proxy<Target, Mutex>, Default_init_allocator, construct_at(), default_init_at(), and pointer-math/alignment free functions.
  • flow.log: Bug fix: Logging near thread death -- such as from the destructor of a thread_local object -- could hit undefined behavior, because certain thread-local flow.log facilities may by then be deinitialized. flow.log: Logging near thread exit (e.g., from a thread_local object's destructor) may hit undefined behavior. #116
  • flow.log: Perf improvements at every log call site that passes the verbosity filter; and when writing message strings in ~all flow::log::Loggers.
  • (flow::log::Log_context_mt, flow::util::Thread_local_state_registry, Polled_shared_state: please disregard their API descriptions in (See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-nov] to base-branch [main]. #111 (not released); their final forms are described in API notes below.)
  • flow.util: flow::util::Linked_hash_map and Linked_hash_set: perf improvements. (Adds to (See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-nov] to base-branch [main]. #111, which improved them quite a bit: no key copying/key need not be copyable.)
  • NetFlow (flow::net_flow): minor bug fixes (~no splash radius).
  • Build scripts: Flow and Flow-like projects now fail the build if an export-worthy header is not actually exported.
  • Significantly expand unit-test coverage: many new tests (including for ~all new APIs above) and expand existing ones. flow: Unit tests (more of them) needed. #82
  • GitHub CI pipeline:
  • Coding guide: several additions.
  • Comment and/or doc changes.

API notes

  • New/improved APIs:
    • In flow::util:
      • stat sub-namespace:
        • Operations on a stat-set (a struct of stats with a declare_stats() member): stats_to_ostream(), stats_reset(), stats_assign(), stats_aggregate(), stats_aggregate_one(), stats_aggregate_shards(), stats_reset_shard_aggregate(), stats_sum(), stats_field_names(), stats_mark_reset_state(), stats_since_reset_state().
        • Per-stat helpers that work the same on plain and atomic members: load(), store(), fetch_add(), fetch_sub(), update_hi_wmark().
        • Histogram_counter; Stat_set_list; Global_stats; Stat_name.
      • As pertains to thread-local state:
        • Thread_local_ptr<T>: semantically identical to boost::thread_specific_ptr<T> but with significantly faster .get().
        • Thread_local_obj_deinit_safe<T, Tag>: equivalent to a naked thread_local T, but for non-trivially-destructible T guards access to the object, yielding null if the object has been destroyed near thread exit.
        • this_thread_unique_token() (and type Thread_token): similar to this_thread::get_id() but guaranteed never to recycle values.
        • Thread_local_state_registry<T> (supersedes its description in (See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-nov] to base-branch [main]. #111): maintains a thread-local T per thread, created on-demand via this_thread_state() and deleted when its thread exits or the registry is destroyed, whichever happens first. To access all extant threads' Ts, call while_locked(task); task receives the registry's map of extant Ts, valid only during task().
        • Poll_flag: a single boolean flag, armed via arm_next_poll() (typically from another thread) and both checked and disarmed via poll_armed(), cheaply enough for the hottest of paths.
        • Polled_shared_state<Shared_state> (supersedes its description in (See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-nov] to base-branch [main]. #111): optional companion to Thread_local_state_registry, for the pattern wherein one embeds a Poll_flag in each thread's T and arms them all to signal a rare cross-thread request, which each thread notices cheaply on its fast-path. Shared_state carries any state about that request, accessed via while_locked().
      • Action_registry: a simple singleton template (with a tag parameter separating registries); code sites (particularly singleton initializers) can register actions (functors); other code can execute all actions in registration order, passing args to each.
      • Locked_proxy<Target, Mutex>: proxy-pointer class template for the execute-around-pointer idiom.
      • Default_init_allocator: allocator for STL-compliant containers that avoids zeroing things like PoDs or array<>s.
      • construct_at(), mimicking the C++20 STL facility of the same name; default_init_at(), reminiscent of C++23 std::start_lifetime_as().
      • Pointer-math/alignment free function templates: is_power_of_two(), max_align_sz(), aligned_sz_of(), aligned_prefix_before(), after_aligned_prefix().
      • String_view::starts_with() and ends_with() are now constexpr.
      • setup_auto_cleanup() takes its functor via move semantics.
    • In flow::cfg:
      • value_set_member_id_to_opt_name(): new optional arg sep_replacement.
    • In flow::log:
      • Log_context_mt (supersedes its description in (See description!) Pull request for repo [flow] branch [ipc-143_perf-dive-nov] to base-branch [main]. #111): variant of Log_context whose Logger* can be changed thread-safely via set_logger(); the mutex also protects copy/move and swap().
        • Mutex-locked logging: new macros FLOW_LOG_..._LOCKED() (lock, log, unlock); method log_while_locked() for a custom operation. New macro FLOW_LOG_SET_LOCKED_CONTEXT() is to FLOW_LOG_SET_CONTEXT() what FLOW_LOG_..._LOCKED() is to FLOW_LOG_...().
        • Unlike Log_context, it has no get_logger() or get_log_component() (an unlocked accessor would defeat the purpose).
  • Breaking changes:
    • flow::util::Basic_blob<>::Allocator_raw alias renamed to Allocator.
    • flow::log::Msg_metadata::m_call_thread_nickname is now of type log::Fixed_string (new alias for boost::static_string<128>) instead of std::string; thread nicknames are truncated to 128 characters. (Affects mainly custom Logger implementations. Needed so that logging works even during thread_local deinit.)
    • Remove flow::util::bind_ns namespace alias.
    • Build scripts (affects Flow-like projects -- such as Flow-IPC -- using Flow's core build script(s)): build now fails if an export-worthy #includeee is not exported. Doc-only headers (such as concept docs) must be listed in new list DOC_ONLY_HDRS.

Impl notes

  • flow.log perf:
    • Three uses of thread_specific_ptr replaced by C++ built-in thread_local; all are exercised at every log call site that passes the verbosity filter.
    • Per-call-site lookup in the thread-local map keyed by Logger* uses a faster data structure.
    • Config::output_component_to_ostream() (used by ~all Loggers when writing the message) uses a faster data structure for component lookups.
  • Thread_local_state_registry uses the new, faster Thread_local_ptr internally.
  • Linked_hash_map and Linked_hash_set internally use open-addressed boost::unordered_flat_set lookups instead of unordered_set.
  • Uniq_id_holder: slightly faster ID generation (relaxed memory-order); local static to avoid any init-misordering issue.
  • util::stat field-name computation is lazy (no cost when not pretty-printing).
  • NetFlow bug fixes:
    • net_flow::Event_set::events_wanted(), net_flow::Node::set_options() and ctor, net_flow::Peer_socket::set_options(): in non-throwing form, did not set *err_code to falsy on success (left it alone).
    • NetFlow options sanity-validator, due to a typo, skipped several intended checks of custom settings.
  • GitHub CI pipeline:
    • Conan 1 => 2 migration. Remove vendored-Boost-recipe kludge, as Conan-2 conan-center has boost/1.87.0. flow + Flow-IPC: CI pipeline: Conan 1.x => 2 #115
    • Knob to specify a filter string when triggering the pipeline, so only some jobs run.
    • "Early-warning" jobs: test against the newest conan-center-available versions of key dependencies (for Flow: Boost), in addition to the min-supported ones.
    • Generate core files for crashes of demo/test programs; generate readable stack traces as artifacts near the existing logs.
    • LSAN suppressions moved to src/sanitize, so they apply to all test binaries and to the dependent Flow-IPC pipeline.
  • Coding guide: template-parameter naming; naming vis-a-vis units and time math; relaxed rule against explicit inlining; include-what-you-use.

To code reviewer

This has been reviewed elsewhere, including with: 🤖 Claude Code

ygoldfeld and others added 30 commits August 10, 2026 17:24
…comparisons in new unit tests; Doxygen cross-namespace link.
…iberate-leak death test); add Conan dependency caching to pipeline.
…ify a filter string when triggering the pipeline, so that only some jobs run.
… test binaries and to the dependent Flow-IPC pipeline.
…/build trees before saving. Documentation: _LOCKED log macros: note the C++17 structured-bindings restriction.
…p Conan cache sizes down by pruning dep source/build trees before saving.
…: remove vendored-Boost-recipe kludge, as Conan-2 conan-center has boost/1.87.0 (the Conan-1 remote was frozen before 1.87 landed, making the kludge mandatory until now).

Details:
- Conan (+ PyYAML) now installed, at requirements.in-specified versions, into a Python venv via pip-tools (new requirements.in); each Conan-wrangling step sources the venv.
- Custom sanitizer settings: mutate-settings.yml approach replaced by the Conan-2 settings_user.yml overlay; matrix defs now supply the full overlay dict.
- Conan profile remains a workspace file, now passed explicitly via -pr:a -- to conan install and (newly needed) conan build, which in Conan 2 recomputes the dep-graph; profile thus still participates in the dep-cache key via hashFiles().
- Dep-cache steps: path ~/.conan/data -> ~/.conan2/p; key prefixes conan-data- -> conan2-data- so stale Conan-1 caches cannot restore (per the TODO planted there).
- Post-install source/build-tree prune: conan remove --builds --src --force -> conan cache clean '*' --source --build.
- Option scoping: flow: -> flow/*:.  Dropped Conan-1-only tools.env.virtualenv:auto_use conf.
- Install step: make install DESTDIR -> cmake --install --prefix (same final tree); install-root-dir env var retired.
- conanfile.py: boost requires-string loses the kludge "@" and its comment block; also removed an accidental duplicate layout() def.
- conan/: vendored boost recipe deleted; README.txt kept (documents the general borrowed-recipe convention; the dir reaches its preferred-empty state).
…unterpart: shared explanations now live in that file, with this one referring to them (previously the split was ad-hoc); consistent reference wording; a few comments that were missing on one side filled in. Also ported from that counterpart: flag-snapshot guard making the dep-cache restore-keys fallback safe; job-level timeout-minutes bound; OS-release info print in the apt step.
…...} form; straggling 0-for-null instances to nullptr.
…::Node::set_options() and ctor, net_flow::Peer_socket::set_options(), if used in non-throwing form, did not set *err_code to falsy on success. / Minor bug fix: NetFlow options sanity-validator, due to a typo, skipped several intended checks of custom settings as optionally set by a user. Splash radius of both: tiny, as this is a demo/test module. / Comment and/or doc changes.
…rt-worthy header is not actually exported by the build; doc-only headers (e.g., concept docs) belong in the new optional DOC_ONLY_HDRS list. / Added public utility APIs util::construct_at() (mimicking the C++20 STL facility) and util::default_init_at() (reminiscent of C++23 std::start_lifetime_as()). / Comment and/or doc changes.
…et with (), not {}, avoiding initializer-list-ctor pitfalls in forwarding code.
…instream jobs, which test against the min-supported versions of key dependencies (for Flow: Boost), a few jobs test against the newest conan-center-available versions of the same, so upstream changes are noticed before such a version becomes the min/default. Also: 2 comments updated for boost.asio 1.90+ (default associated executor).
…ow. The conan-center boost/1.91.0 recipe fails its own library-consistency check with our option set ("These libraries were built, but were not used in any boost module: boost_regex", though b2 reports regex as not building); bisecting.
… for now (conan-center boost/1.91.0 recipe consistency-check failure with our option set).
…ost.Regex no longer excluded in conanfile.py: the conan-center boost/1.91.0 recipe built boost_regex anyway (some module we build now needs it) and then failed its own library-consistency check ("built, but were not used in any boost module: boost_regex"); same class of problem, and same disposition, as the 1.87 `context` case already noted in conanfile.py.
…no longer excluded in conanfile.py (comment explains); comment tweaks.
…eadSanitizer build (for skipping tests TSAN cannot follow).
…rams; at the end of the job generate readable stack traces, available as artifacts near the existing logs. Plus comment and/or doc changes.
…peeding up various operations including making it possible to avoid all copying of `Key`s. Also general speed improvement by leveraging `unordered_flat_...` (open-addressed) lookups internally instead of the vanilla `unordered_` lookups. Added pointer-stability unit test for `Linked_hash_map/set`. `util::stat` now uses lazy evaluation (new `Stat_name`) to avoid computing field names and prefixes when the op has nothing to do with pretty-printing names.
…o not rely on transitive including). For Linked_hash_map/set added tests of move-only keys/values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kwu1pnHVN84wqQRauxuCfg
…_flat_map perf sweep (log, struc::Channel, SHMJ Thread_cache); test-util pool-name sanitize; doc/to-do updates.
…ools, arena-create errors, Shm_session teardown race + liveness via new session::Session_cfg, fancy-pointer fast <=/>=/difference + signed-division fix); docs/tests.
…with STL-compliant containers to avoid zeroings of things like PoDs or `array<>`s when used within other containers. / Comment and/or doc changes.
@ygoldfeld ygoldfeld self-assigned this Nov 3, 2026
@ygoldfeld
ygoldfeld merged commit e45618a into main Nov 3, 2026
52 checks passed
@ygoldfeld

Copy link
Copy Markdown
Contributor Author

This fixed #76 also

@ygoldfeld

Copy link
Copy Markdown
Contributor Author

This fixed #119 also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant