Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Dec 18, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? đź’– Please sponsor : )

Fixes #12610 

### Context

Follow-up to #12577. The taskhost node identification used bit-packing
to combine `scheduledNodeId` (8 bits) and `HandshakeOptions` (9 bits)
into a single int, limiting multithreaded builds to 256 nodes. This
approach was fragile and hard to maintain.

### Changes Made

- **New `TaskHostNodeKey` record struct** in
`CommunicationsUtilities.cs` combining `HandshakeOptions` and `NodeId`
as a clean, type-safe key
- **Updated `NodeProviderOutOfProcTaskHost`** with optimized dictionary
structure:
- `_nodeContexts` keyed by `TaskHostNodeKey` for checking if a node with
given (HandshakeOptions, scheduledNodeId) exists (acquisition logic)
  - `_nodeIdToNodeKey` for O(1) reverse lookup during node termination
- `_nodeIdToPacketFactory` and `_nodeIdToPacketHandler` keyed by int for
O(1) packet routing performance
  - `_activeNodes` tracks node IDs (int) for shutdown handling
- Added atomic `_nextNodeId` counter for unique communication node ID
generation
- **Simplified `TaskHostTask`** - removed `GenerateTaskHostNodeId`
method and associated bit-packing constants
- **Improved error handling** - Added `VerifyThrow` assertions in
`DisconnectFromHost` and `CreateNode` to verify context existence and
prevent duplicate nodes

```csharp
// Before: bit-packed int with 256-node limit
_taskHostNodeId = GenerateTaskHostNodeId(_scheduledNodeId, _requiredContext);
// (scheduledNodeId << 9) | ((int)handshakeOptions & 0x1FF)

// After: clean record struct, no limit
_taskHostNodeKey = new TaskHostNodeKey(_requiredContext, _scheduledNodeId);
```

This gives the best of both worlds:
- **Maintainability**: Type-safe Keys for managing node lifecycle and
acquisition
- **Performance**: Direct Integer lookups for the high-frequency packet
routing hot path

### Testing

- Added 7 unit tests for `TaskHostNodeKey` (equality, hash codes,
dictionary keys, large node IDs)
- All 86 existing TaskHost tests pass

### Notes

- Removes the `NODE_ID_MAX_VALUE_FOR_MULTITHREADED` (255) constraint
entirely
- `SendData(int, INodePacket)` throws `NotImplementedException` as it's
required by `INodeProvider` interface but not used for task hosts
(similar to `TaskHostNodeManager`)

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[multithreaded] Refactor Node IDs for
taskhost</issue_title>
> <issue_description>followup to #12577
> Refactor
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs
, HandshakeOptions to use record struct as a key to nodes to increase
maintanability and remove limitation to 256 nodes.</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>

- Fixes #12610

<!-- START COPILOT CODING AGENT TIPS -->
---

đź’ˇ You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JanProvaznik <[email protected]>
Co-authored-by: Jan ProvaznĂ­k <[email protected]>
Co-authored-by: Copilot <[email protected]>
@pull pull bot locked and limited conversation to collaborators Dec 18, 2025
@pull pull bot merged commit 9263fe6 into thompson-tomo:main Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants