Repository navigation
No singletons, state: startup hooks, default shard, codecs and threading per app [4.0, breaking] - #1182
Closed
transfix wants to merge 1 commit into
Closed
No singletons, state: startup hooks, default shard, codecs and threading per app [4.0, breaking]#1182transfix wants to merge 1 commit into
transfix wants to merge 1 commit into
Conversation
…ing per app src/cvc/state (except state_exec) and state_object<T> keep no process-wide state. What each static held moves onto the app (app::slot) or into the object that uses it. Moved: - state::on_startup: the process-wide _startup/_appStartup registries, their mutex and id counter become the app's own hooks (slot cvc.state.startup-hooks). on_startup(app &, f) runs f once for that app, when its root is made, or at once if it was made already; a startup_connection names the hooks weakly, so it may outlive the app. The built-in __system.start default (and, with USING_XMLRPC, the __system.xmlrpc monitor) run from state::instance() itself instead of file-scope static registrars. - state_cluster_shard::default_for(app &): the default-shard map keyed by app address (never pruned, so a new app at a dead one's address could inherit its shard) becomes a per-app cell (cvc.state.default-shard). A shard keeps the cell it installed itself in, so uninstalling never touches the app. send_message's process-wide id counter becomes a per-shard random tag plus a count, so a shard made again under the same node id repeats no id (a peer's bus would drop it). - state_compression_registry::shared(app &): the process-wide registry is the app's own (cvc.state.compression-registry); shards and the session's hydrator use their app's. - state_sync_adapter: the thread_local suppression depth, shared by every adapter in the process, becomes the app's (cvc.state.sync-suppression): the threads applying a remote mutation to the app, or in a suppression_scope on it. A remote apply on one app no longer hides a local change to another app made on the same thread (an inproc fan-out, or a slot the apply sets off). - register_volume_geometry_codecs(app &, registry): decoded volumes and geometries were made on a thread_local app (one hidden app per thread, gone at thread exit while the decoded object may live on); they are now the registering app's (the shard's). - state_object<T>::_useThreading (a per-type static flag, in cvc, volren, volslice and cvcGL instantiations) becomes the app's default (set_state_object_threading(app &, bool), state_object_threading(app &); cvc.state.object-threading); setInstanceThreading still overrides it per object. setUseThreading/getUseThreading are gone. cvcGL and volren only use setInstanceThreading, so they are unchanged. - state_json_reader: the thread_local write-pin stack is the reader's own member. - state_delta_codec: the CRC-32 table is constexpr (read-only data). - state_transport_ws: the CVC_WS_BROADCAST_DEBUG flag is read each broadcast (about once a second) instead of cached in a function-local static. - grpc_dns_resolver.h (Windows only, not in the scan): the once_flag goes; setting GRPC_DNS_RESOLVER again when it is already set is harmless. - state_device_key / state_identity: hex digit tables are constexpr arrays. Tests (several apps each: two apps in both orders, apps on threads at once, a later app made after another is gone starts clean): - state_test: on_startup per app (runs once, at once after the root, disconnect, apps on threads, a handle outliving its app); state_object threading per app (replaces the per-template-type test) and on threads; the threading tests no longer restore a global. - state_send_message_test: default shard per app, on threads, and message ids that survive a shard made again under the same node id. - state_sync_adapter_test: suppression per app (and shared by an app's adapters), a remote apply on one app not hiding another app's change, apps on threads. - state_compression_registry_test: each app has its own registry, on threads. - state_volume_codec_test: decoded objects belong to the registering app, on threads. - state_deep_tree_test: json readers of several apps interleaved on one thread and on threads. - multi_app_integration_test: the state_layer workload part (default shard and message, compression codecs, state_object threading default, startup callback, decoded volume). Allowlist: 32 lines removed (cvc 23, cvcGL 9).
This was referenced Nov 12, 2026
Closed
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No singletons, state: startup hooks, the default shard, codecs and threading per app. Stacked on #1176 (Ariadne part 3). Breaking (4.0).
src/cvc/state(notstate_exec, which is its own PR) keeps no process-wide state now. Nothing in this area needed to stay process-wide.What moved, and the bugs it fixes
cvc.state.startup-hooks). A hook runs once, when that app's root is made, or at once if the root already exists.startup_connectionholds the hooks weakly, so it can outlive its app.__system.startis set bystate::instance()itself; the file-scope registrars are gone. WithUSING_XMLRPC, the__system.xmlrpcmonitor starts there too, throughxmlrpc_server_startup(app&). That build is off by default, so it was only syntax-checked.cvc.state.default-shard). Bug fixed: the old map was keyed byapp*and never pruned, so a new app at a dead app's address inherited its shard. A shard keeps a reference to the cell it installed itself in, so uninstalling never touches the app.send_message's ids are a random per-shard tag plus a count, not a process-wide sequence. Bug fixed: a shard made again under the same node id repeated ids, and a peer's bus drops repeats. The header comment wrongly said an empty id stays empty; that is corrected.shared(app&), the app's own (slotcvc.state.compression-registry). Shards and the session's hydrator use their app's.cvc.state.sync-suppression). Bug fixed: a remote apply on one app hid local changes made on the same thread to a different app (an in-process fan-out, or a slot the apply triggers).state_object<T>::_useThreading(one flag per template type, in a header) is a per-app default, withsetInstanceThreadingstill overriding it per object. cvcGL and volren only usesetInstanceThreading.state_json_reader;constexpr;once_flagingrpc_dns_resolver.his gone (setting the variable again is harmless);state_device_key/state_identityareconstexpr.Public API changes
state::on_startup(app&, f), both overloads.state::_startup,_appStartupand the init-vector typedefs are gone.state_cluster_shard::default_for(app&).state_compression_registry::shared(app&).register_volume_geometry_codecs(app&, registry).state_object<T>::setUseThreading/getUseThreadingare replaced byset_state_object_threading(app&, bool)/state_object_threading(app&).pycvc.idrops its%ignores for the removed statics.Allowlist: -32 lines (cvc 23, cvcGL 9)
state.cpp(the startup counter, mutex, guard and the two vectors);state_cluster_shard.cpp(the default registry, its mutex and guard, andsend_message's sequence);state_json.cpp's pin stack;state_sync_adapter.cpp's depth;state_volume_codec.cpp's two decode contexts and guards;_useThreadingfor volren's and volslice's settings (cvc) and nine cvcGL types.Tests
Two apps in both orders, apps on threads, and a later app starting clean, in:
state_test(the startup hooks; threading per app and on threads);state_send_message_test(the default shard per app; ids after a shard is made again);state_sync_adapter_test(suppression per app; another app's change not hidden);state_compression_registry_test;state_volume_codec_test(decoded objects belong to the registering app);state_deep_tree_test(JSON readers for several apps).multi_app_integration_testgains astate_layerpart: the default shard and a message, compression codecs, the threading default, a startup callback and a decoded volume.Locally (Windows, MSVC Release):
state_delta_codec_test,state_cluster_shard_test,distributed_state_session_test,geometry_height_field_test;app_test121,multi_app_integration_test,volren_state_test,volslice_state_test;cvc_cli_testState* (14),cvcgl_camera,cvcgl_fps_hud;Not built on Windows (conditional):
state_transport_ipc_test(updated forshared(app&)),state_transport_ws_test,stream_bridge_test,room_relay_integration_test. CI builds them.CI
Full run: the push to
ci/full/no-singletons-state, https://github.com/transfix/libcvc/actions/runs/43206788348.