Skip to content

Using pointer address as node/symbol id #650

Open
@JoostK

Description

@JoostK

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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions