The fantastic ORM library for Golang, aims to be developer friendly
Go to file
Jeremy Quirke 8c18714462
Don't call MethodByName with a variable arg (#6602)
Go 1.22 goes somewhat toward addressing the issue using reflect
MethodByName disabling linker deadcode elimination (DCE) and the
resultant large increase in binary size because the linker cannot
prune unused code because it might be reached via reflection.

Go Issue golang/go#62257 reduces the number of incidences of this
problem by leveraging a compiler assist to avoid marking functions
containing calls to MethodByName as ReflectMethods as long as the
arguments are constants.

An analysis of Uber Technologies code base however shows that a number
of transitive imports still contain calls to MethodByName with a
variable argument, including GORM.

In the case of GORM, the solution we are proposing is because the
number of possible methods is finite, we will "unroll" this. This
demonstrably shows that GORM is not longer a problem for DCE.

Before
```
% go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
% go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
gorm.io/gorm.(*Statement).BuildCondition -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
gorm.io/gorm/clause_test.BenchmarkComplexSelect -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/migrator	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
gorm.io/gorm/schema_test.TestAdvancedDataTypeValuerAndSetter -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```

After

```
%go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
%go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
?   	gorm.io/gorm/migrator	[no test files]
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```
2023-10-10 14:50:29 +08:00
.github Update go testing versions 2023-08-24 20:19:38 +08:00
callbacks Clear SET clause after build SQL 2023-05-15 15:43:44 +08:00
clause feat: reuse name (#6626) 2023-10-10 14:45:48 +08:00
logger add float32 test case (#6530) 2023-08-19 21:33:57 +08:00
migrator fix: sqlite dialector cannot apply `PRIMARY KEY AUTOINCREMENT` type (#6624) 2023-10-09 17:26:27 +08:00
schema Don't call MethodByName with a variable arg (#6602) 2023-10-10 14:50:29 +08:00
tests fix: sqlite dialector cannot apply `PRIMARY KEY AUTOINCREMENT` type (#6624) 2023-10-09 17:26:27 +08:00
utils *datatypes.JSON in model causes panic on tx.Statement.Changed (#6611) 2023-10-10 14:46:32 +08:00
.gitignore Adjust ToStringKey use unpack params, fix pass []any as any in variadic function (#5500) 2022-07-14 20:05:22 +08:00
.golangci.yml feat: golangci add goimports and whitespace (#5835) 2022-11-05 08:37:37 +08:00
LICENSE renamed License to LICENSE (#6336) 2023-05-21 21:24:00 +08:00
README.md Update README 2023-04-11 13:16:25 +08:00
association.go feat: unscoped association (#5899) (#6246) 2023-05-04 19:30:45 +08:00
callbacks.go debug: use slice Stale sort (#6263) 2023-04-26 22:19:46 +08:00
chainable_api.go fix typo chainable_api.go (#6266) 2023-04-26 22:19:06 +08:00
errors.go Added support of "Violates Foreign Key Constraint" (#6329) 2023-05-21 21:27:22 +08:00
finisher_api.go fix: save with hook (#6285) (#6294) 2023-05-26 10:28:02 +08:00
go.mod Update go.mod 2023-08-27 15:40:54 +08:00
go.sum feat: rm GetDBConnWithContext method (#6535) 2023-08-19 21:33:31 +08:00
gorm.go Fixed error message when dialector fails to initialize (#6509) 2023-08-20 19:46:56 +08:00
interfaces.go feat: rm GetDBConnWithContext method (#6535) 2023-08-19 21:33:31 +08:00
migrator.go feat: migrator support table comment (#6225) 2023-05-05 15:58:27 +08:00
model.go Issue 6054: Unscoped not working with PreLoad on Joins (#6058) 2023-02-18 09:06:43 +08:00
prepare_stmt.go feat: rm GetDBConnWithContext method (#6535) 2023-08-19 21:33:31 +08:00
scan.go feat: support nested join (#6067) 2023-03-10 17:21:56 +08:00
soft_delete.go fix: support zeroValue tag on DeletedAt (#6011) 2023-02-01 14:40:55 +08:00
statement.go fix cond in scopes (#6152) 2023-04-11 12:01:23 +08:00
statement_test.go fix: ignore nil query (#6021) 2023-02-02 17:54:51 +08:00

README.md

GORM

The fantastic ORM library for Golang, aims to be developer friendly.

go report card test status MIT license Go.Dev reference

Overview

  • Full-Featured ORM
  • Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism, Single-table inheritance)
  • Hooks (Before/After Create/Save/Update/Delete/Find)
  • Eager loading with Preload, Joins
  • Transactions, Nested Transactions, Save Point, RollbackTo to Saved Point
  • Context, Prepared Statement Mode, DryRun Mode
  • Batch Insert, FindInBatches, Find To Map
  • SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints, NamedArg, Search/Update/Create with SQL Expr
  • Composite Primary Key
  • Auto Migrations
  • Logger
  • Extendable, flexible plugin API: Database Resolver (Multiple Databases, Read/Write Splitting) / Prometheus…
  • Every feature comes with tests
  • Developer Friendly

Getting Started

Contributing

You can help to deliver a better GORM, check out things you can do

Contributors

Thank you for contributing to the GORM framework!

License

© Jinzhu, 2013~time.Now

Released under the MIT License