microsoft / microsoft/STL

<xtree>: Consider encoding _Color and _Isnil in the least significant bits of a node pointer

Open
#291 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance vNext
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

map and set nodes are currently represented with:

https://github.com/microsoft/STL/blob/58bb49d63d92e7a0346a05af29816aeea6b4cf0f/stl/inc/xtree#L321-L330

This consumes a surprising amount of space. At first glance, _Color and _Isnil consume a total of 2 bytes, but because the node contains pointers, they actually consume a total of 4 bytes (for 32-bit architectures) or 8 bytes (for 64-bit architectures), due to alignment.

We could potentially encode these bits into one of the pointers, saving a significant amount of space, at the cost of additional bit-masking logic. (There are also "fancy pointers" to consider, but we could enable such an optimization for raw pointers only.)

Also tracked by Microsoft-internal VSO-854783 / AB#854783.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the node representation in stl/inc/xtree around lines 321-330, then investigate how raw and fancy pointers affect layout and alignment. Any implementation must preserve the relevant pointer behavior while reducing node size, and cannot be proposed for acceptance until the vNext branch is available because it breaks binary compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.