jcrist · GitHub

This adds a new nogc option for msgspec.Struct types, which disables the cyclic garbage collector for that class. This is an advanced optimization that may benefit some workloads, at the cost of relying on the programmer not accidentally creating reference cycles. This is most likely to benefit workloads where many struct types are created at once (e.g. decoding a large message) or workloads where there are many many long lived struct objects.

Note that struct types composed of only untracked objects (e.g. ints, strs, ...) are already untracked themselves (applying a similar GC optimization that cpython applies to dicts). This optimization is safe in the presence of cycles, and is applied automatically. Setting nogc=True will also disable GC for structs containing container types (lists, dicts, structs, ...) where there is a chance that a reference cycle may occur. It is the user's responsibility to ensure that cycles don't occur when setting nogc=True.

Read the original on github.com ↗