Skip to content

C#: create the sender and receiver models on first use - #114

Open
jccarvalhosa wants to merge 1 commit into
chronoxor:mainfrom
TOOQ-TECHNOLOGY:lazy-csharp-message-models
Open

jccarvalhosa wants to merge 1 commit into
chronoxor:mainfrom
TOOQ-TECHNOLOGY:lazy-csharp-message-models

Conversation

@jccarvalhosa

Copy link
Copy Markdown

The generated Sender, Receiver, Proxy and Client created the model of every message of the protocol in their constructors, and the Receiver and Client also built the Default value of every message. Each model is a distinct generic instantiation over the message struct, so the first Sender or Receiver of a process made the JIT compile all of them before a single message went out, whichever messages the process actually used: a protocol with a few hundred message and field models spent a noticeable part of a client's start-up there.

Each model is now created the first time its message is sent or received, behind a property of the same name, so existing code reading Sender.XModel or Client.XSenderModel compiles unchanged. Once a model exists the access is a null check, with no further allocation. The received value fields are no longer initialized with Default, since every receive assigns them through Deserialize(out ...) before they are read.

The generated Sender, Receiver, Proxy and Client created the model of
every message of the protocol in their constructors, and the Receiver and
Client also built the Default value of every message. Each model is a
distinct generic instantiation over the message struct, so the first
Sender or Receiver of a process made the JIT compile all of them before a
single message went out, whichever messages the process actually used: a
protocol with a few hundred message and field models spent a noticeable
part of a client's start-up there.

Each model is now created the first time its message is sent or
received, behind a property of the same name, so existing code reading
Sender.XModel or Client.XSenderModel compiles unchanged. Once a model
exists the access is a null check, with no further allocation. The
received value fields are no longer initialized with Default, since every
receive assigns them through Deserialize(out ...) before they are read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant