microsoft / microsoft/TypeScript

Using pointer address as node/symbol id

Open
#63,773 5 comments 0 reactions 0 assignees View on GitHub
Domain: Performance
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Nodes and symbols currently store an atomic integer representing their ID, which is lazily assigned upon first use. I was playing with using the pointer addresses as their ID, reducing the size of those structures and avoiding atomic reads on access.

```go
func GetNodeId(node *Node) NodeId {
return NodeId(uint64(uintptr(unsafe.Pointer(node))))
}

func GetSymbolId(symbol *Symbol) SymbolId {
return SymbolId(uint64(uintptr(unsafe.Pointer(symbol))))
}
```

A potential downside is that `KeyBuilder` will observe larger numbers, requiring additional bytes to represent various keys. It may also affect ordering as IDs will no longer be strictly increasing, but I believe this shouldn't matter given that ID assignment is already non-deterministic.

A quick attempt passes the `hereby test` and shows a slight reduction in overall memory usage, but I don't have good insight into actual performance benfits/downsides of this approach.

I am opening this as issue instead of PR to discuss, possibly to learn this has been considered and may have been rejected for some reason. I'd be happy to open a PR if desired.

Contributor guide

Open the contributing guide

Research direction

Start by reading the GetNodeId and GetSymbolId examples, then inspect how KeyBuilder represents IDs. Run hereby test to reproduce the reported baseline; the issue does not define acceptance criteria beyond discussing memory, performance, key size, and ordering effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.