Skip to content

Add WithDisableTopology option to reduce memory consumption#432

Closed
halfcrazy wants to merge 1 commit intojaypipes:mainfrom
halfcrazy:disable-topo
Closed

Add WithDisableTopology option to reduce memory consumption#432
halfcrazy wants to merge 1 commit intojaypipes:mainfrom
halfcrazy:disable-topo

Conversation

@halfcrazy
Copy link
Copy Markdown
Contributor

@halfcrazy halfcrazy commented Nov 6, 2025

This commit adds a new WithDisableTopology() option that allows users to skip system topology detection when calling ghw.PCI() or ghw.GPU(), significantly reducing memory consumption for use cases that don't require NUMA topology information.

Performance impact on real production servers:

Dual-socket server (2 NUMA nodes, 96 cores):
BenchmarkPCIMemoryComparison/WithTopologyDetection 100 100708875 ns/op 29332384 B/op 289365 allocs/op
BenchmarkPCIMemoryComparison/WithDisableTopology 100 58473485 ns/op 17201283 B/op 247006 allocs/op

  • Memory: 41% reduction (28 MB -> 16.4 MB)
  • Time: 42% faster (100.7 ms -> 58.5 ms)
  • Allocations: 15% fewer (289,365 -> 247,006)

Quad-socket server (4 NUMA nodes, 128 cores):
BenchmarkPCIMemoryComparison/WithTopologyDetection 100 448132406 ns/op 344566098 B/op 257009 allocs/op
BenchmarkPCIMemoryComparison/WithDisableTopology 100 64284435 ns/op 18707107 B/op 193877 allocs/op

  • Memory: 94.6% reduction (328 MB -> 17.8 MB)
  • Time: 85.7% faster (448 ms -> 64 ms)
  • Allocations: 24.6% fewer (257,009 -> 193,877)
  • Saves 310 MB per call - critical for large deployments

@halfcrazy
Copy link
Copy Markdown
Contributor Author

xref #354

@jaypipes
Copy link
Copy Markdown
Owner

jaypipes commented Jan 8, 2026

Hi @halfcrazy sorry this has lagged. I will have to rework this PR due to a refactoring that recently merged as we head towards a 1.0 release of ghw. I will try to get to the reworking of this PR this weekend.

@halfcrazy halfcrazy force-pushed the disable-topo branch 2 times, most recently from d16c5ed to 2b168d0 Compare January 13, 2026 08:24
}
info.arch = topo.Architecture
}
if opts.PCIDB != nil {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found options.PCIDB no longer used, i'm not sure if this is expected.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author

@halfcrazy yes, we've totally changed the way that options and context are handled. I will rework this PR soon, I promise. sorry for the delay.

This commit adds a new WithDisableTopology() option that allows users
to skip system topology detection when calling ghw.PCI() or ghw.GPU(),
significantly reducing memory consumption for use cases that don't
require NUMA topology information.

Signed-off-by: Yan Zhu <hackzhuyan@gmail.com>
Copy link
Copy Markdown
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halfcrazy sorry it took so long, but I rebased and fixed up your commit to use the latest config/context handling:

#449

@halfcrazy
Copy link
Copy Markdown
Contributor Author

@halfcrazy sorry it took so long, but I rebased and fixed up your commit to use the latest config/context handling:

#449

thank you

@halfcrazy halfcrazy closed this Feb 9, 2026
@jaypipes jaypipes mentioned this pull request Feb 9, 2026
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.

2 participants