A fast, feature-rich deep-copy library for Go with support for complex type conversions and custom copying behaviors.
go-deepcopy is a Go library that performs fast and flexible deep copying of data structures. It solves the problem of manually copying complex nested types by providing a reflection-based API that supports copying between different types, custom field mappings, and post-copy hooks.
Go developers working with complex data structures, serialization, or data transformation tasks, especially those needing to copy data between different struct types or convert types during copying.
Developers choose go-deepcopy for its combination of speed, extensive feature set, and configurability, outperforming many alternative libraries in benchmarks while offering advanced features like zero-to-nil conversion and custom copy methods.
Fast deep-copy library for Go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
In benchmarks, it significantly outperforms popular alternatives like jinzhu/copier and mohae/deepcopy in both speed and memory usage, making it one of the fastest deep-copy libraries available.
Supports copying between convertible types (e.g., int to float) and between pointers and values, enabling seamless data transformation without manual code.
Uses struct tags to copy between fields with different names, skip fields, or require copying, providing fine-grained control as shown in the field mapping and skip examples.
Allows structs to define Copy<field> methods and PostCopy hooks for custom copying and post-processing, adapting to complex business needs with examples in the README.
Despite being fast among libraries, it's still slower than manual copying due to reflection, with benchmarks showing it's about 10-20x slower in some cases, which can impact performance-critical paths.
Requires understanding of struct tags, custom methods, and configuration options, which can be error-prone and increase the learning curve, especially for developers new to reflection-based APIs.
As a reflection-based library, type mismatches and errors are only caught at runtime, potentially leading to panics if not handled carefully, such as with unexported fields requiring address passing.