Skip to content

Devirtualization + internal linkage: mark leaf impl classes final and TU-local helpers static#1488

Open
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/devirt-final-static
Open

Devirtualization + internal linkage: mark leaf impl classes final and TU-local helpers static#1488
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/devirt-final-static

Conversation

@bmehta001

@bmehta001 bmehta001 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Devirtualization: mark concrete leaf impl classes final

Marks the leaf concrete implementations of the hot IHttpClient / IOfflineStorage
interfaces final, so the compiler can devirtualize (and frequently inline)
virtual calls made through a known-final type ? smaller, faster code on every
HTTP upload and offline-storage operation.

Marked final (9):

  • HttpClient_Curl, HttpClient_WinInet, HttpClient_WinRt, HttpClient_Apple, HttpClient_Android, HttpClient_CAPI
  • OfflineStorage_Room, MemoryStorage, OfflineStorageHandler

Verification: each was confirmed to have no subclass anywhere in the tree (lib + tests + wrappers).

Deliberately NOT marked:

  • OfflineStorage_SQLite ? tests/unittests/OfflineStorageTests_SQLite.cpp subclasses it (OfflineStorage_SQLiteNoAutoCommit).
  • TelemetrySystemBase ? it's the base of TelemetrySystem / AITelemetrySystem.

Validation: NDK aarch64 -fsyntax-only clean on OfflineStorage_Room, OfflineStorageHandler, MemoryStorage. The platform-specific HTTP impls (WinInet/WinRt/Apple) rely on the no-subclass verification + per-platform CI.

Note on static/anonymous-namespace

The companion static/anon-namespace cleanup for file-local helpers is a planned follow-up. Its primary benefit (keeping internals out of the exported symbol set) is largely already delivered by the -fvisibility=hidden change in the vcpkg PR (#1475), so it's lower priority; static adds the incremental win of stronger inlining/DCE and no symbol entry at all, which can be a focused follow-up.


Internal linkage (static) — added in d0c0afb

Companion micro-optimization in the same spirit: give internal linkage to translation-unit-local symbols so the compiler can inline/drop them and keep them out of the symbol table. This specifically helps the static-library consumption path (e.g. vcpkg), which -fvisibility=hidden does not fully cover — hidden visibility only trims a shared object's dynamic export table, whereas these symbols otherwise keep external linkage across TUs.

  • lib/api/capi.cpp — marked the 10 file-local C-API dispatch helpers static (remove_client, mat_open_core, mat_open, mat_open_with_params, mat_log, mat_close, mat_pause, mat_resume, mat_upload, mat_flushAndTeardown). Each is called only from the single exported entry point evt_api_call_default (and from one another) within capi.cpp, and appears in no header and no other TU. MAT::capi_get_client stays external (header-declared, used by the CAPI HTTP client).
  • lib/shared/dllmain.cpp — marked thread_count static (file-scope global mutated only inside DllMain).

Deliberately not touched: get_platform_uuid (sysinfo_sources.cpp) has no in-tree caller, so static would trip -Wunused-function under -Werror.

Verified: NDK clang aarch64 -fsyntax-only on capi.cpp is clean; whole-tree cross-reference confirmed none of the internalized symbols are referenced from any header or other translation unit.

Mark the leaf concrete implementations of IHttpClient and IOfflineStorage final
so the compiler can devirtualize (and often inline) calls made through them:
HttpClient_{Curl,WinInet,WinRt,Apple,Android,CAPI} and OfflineStorage_Room /
MemoryStorage / OfflineStorageHandler.

Each was verified to have no subclass anywhere in the tree (lib + tests +
wrappers). Deliberately NOT marked:
 - OfflineStorage_SQLite -- tests/unittests/OfflineStorageTests_SQLite.cpp
   subclasses it (OfflineStorage_SQLiteNoAutoCommit).
 - TelemetrySystemBase -- base of TelemetrySystem / AITelemetrySystem.

Validated: NDK aarch64 -fsyntax-only on OfflineStorage_Room, OfflineStorageHandler
and MemoryStorage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 requested a review from a team as a code owner June 18, 2026 22:54
@bmehta001 bmehta001 requested a review from Copilot June 18, 2026 22:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes hot-path virtual dispatch by marking leaf concrete implementations of the IHttpClient and IOfflineStorage interfaces as final, enabling better compiler devirtualization/inlining in the SDK’s HTTP upload and offline-storage code paths.

Changes:

  • Mark concrete HTTP client implementations (HttpClient_*) as final.
  • Mark concrete offline storage implementations/handler (OfflineStorage_*, MemoryStorage, OfflineStorageHandler) as final.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/offline/OfflineStorageHandler.hpp Marks OfflineStorageHandler as final to enable devirtualization through known concrete type usage.
lib/offline/OfflineStorage_Room.hpp Marks OfflineStorage_Room as final to allow devirtualization in Android Room-backed storage path.
lib/offline/MemoryStorage.hpp Marks MemoryStorage as final to enable devirtualization for in-memory storage operations.
lib/http/HttpClient_WinRt.hpp Marks HttpClient_WinRt as final to improve call-site optimization on WinRT HTTP path.
lib/http/HttpClient_WinInet.hpp Marks HttpClient_WinInet as final to improve call-site optimization on WinInet HTTP path.
lib/http/HttpClient_Curl.hpp Marks HttpClient_Curl as final to improve call-site optimization on Curl HTTP path.
lib/http/HttpClient_CAPI.hpp Marks HttpClient_CAPI as final to improve call-site optimization for C API-backed HTTP client.
lib/http/HttpClient_Apple.hpp Marks HttpClient_Apple as final to improve call-site optimization on Apple HTTP path.
lib/http/HttpClient_Android.hpp Marks HttpClient_Android as final to improve call-site optimization on Android HTTP path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Companion to the `final` devirtualization in this PR: give internal
linkage to translation-unit-local symbols so the compiler can inline /
drop them and keep them out of the (static-archive and shared-object)
symbol table. This helps the static-lib consumption path that
-fvisibility=hidden does not fully cover, since hidden visibility only
trims the dynamic export table while these symbols keep external linkage
across TUs.

lib/api/capi.cpp: mark the 10 file-local C-API dispatch helpers static
  (remove_client, mat_open_core, mat_open, mat_open_with_params, mat_log,
   mat_close, mat_pause, mat_resume, mat_upload, mat_flushAndTeardown).
  Verified each is called only from the single exported entry point
  evt_api_call_default (and each other) within capi.cpp, and appears in
  no header and no other translation unit. capi_get_client stays external
  (it is MAT::capi_get_client, declared in a header and used by the CAPI
  HTTP client). Consistent with the file's existing static mtx/clients.

lib/shared/dllmain.cpp: mark thread_count static -- a file-scope mutable
  global mutated only inside DllMain in this TU.

get_platform_uuid (sysinfo_sources.cpp) was deliberately NOT touched: it
has no caller in-tree, so marking it static would trip -Wunused-function
under -Werror.

Verified: NDK clang aarch64 -fsyntax-only on capi.cpp is clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 changed the title Devirtualization: mark concrete leaf impl classes final Devirtualization + internal linkage: mark leaf impl classes final and TU-local helpers static Jun 19, 2026
@bmehta001 bmehta001 requested a review from Copilot June 19, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread lib/api/capi.cpp
Comment on lines 233 to +236
/**
* Marashal C struct to C++ API
*/
evt_status_t mat_log(evt_context_t *ctx)
static evt_status_t mat_log(evt_context_t *ctx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants