kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Structures improvement

Open ilteoood opened this issue 3 years ago • 1 comments

In this PR I've used the fieldalignment tool to improve the structure size in memory.

Here is the output:

$> fieldalignment -fix ./jsoninfo
./jsoninfo/field_info.go:11:16: struct with 56 pointer bytes could be 40
./jsoninfo/unmarshal.go:20:20: struct with 32 pointer bytes could be 16
./jsoninfo/marshal_test.go:12:13: struct with 88 pointer bytes could be 56
./jsoninfo/marshal_test.go:23:22: struct with 88 pointer bytes could be 56
./jsoninfo/marshal_test.go:70:14: struct with 40 pointer bytes could be 32

$> fieldalignment -fix ./openapi2
./openapi2/openapi2.go:147:16: struct with 200 pointer bytes could be 184
./openapi2/openapi2.go:188:16: struct with 256 pointer bytes could be 216
./openapi2/openapi2.go:226:15: struct with 64 pointer bytes could be 56

$> fieldalignment -fix ./openapi2conv

$> fieldalignment -fix ./openapi3
./openapi3/discriminator.go:11:20: struct with 32 pointer bytes could be 24
./openapi3/encoding.go:12:15: struct with 56 pointer bytes could be 48
./openapi3/link.go:31:11: struct with 88 pointer bytes could be 80
./openapi3/loader.go:27:13: struct with 128 pointer bytes could be 112
./openapi3/openapi3.go:13:8: struct with 200 pointer bytes could be 184
./openapi3/operation.go:15:16: struct with 160 pointer bytes could be 136
./openapi3/parameter.go:90:16: struct with 128 pointer bytes could be 112
./openapi3/refs.go:18:18: struct with 24 pointer bytes could be 16
./openapi3/refs.go:55:17: struct with 24 pointer bytes could be 16
./openapi3/refs.go:92:16: struct with 24 pointer bytes could be 16
./openapi3/refs.go:129:14: struct with 24 pointer bytes could be 16
./openapi3/refs.go:154:19: struct with 24 pointer bytes could be 16
./openapi3/refs.go:191:18: struct with 24 pointer bytes could be 16
./openapi3/refs.go:228:21: struct with 24 pointer bytes could be 16
./openapi3/refs.go:265:16: struct with 24 pointer bytes could be 16
./openapi3/refs.go:309:24: struct with 24 pointer bytes could be 16
./openapi3/request_body.go:31:18: struct with 40 pointer bytes could be 24
./openapi3/schema.go:108:13: struct with 392 pointer bytes could be 344
./openapi3/schema.go:1521:18: struct with 96 pointer bytes could be 80
./openapi3/security_scheme.go:224:16: struct with 64 pointer bytes could be 56
./openapi3/server.go:43:13: struct with 48 pointer bytes could be 40
./openapi3/server.go:157:21: struct with 56 pointer bytes could be 48
./openapi3/tag.go:34:10: struct with 48 pointer bytes could be 40
./openapi3/content_test.go:24:13: struct with 48 pointer bytes could be 40
./openapi3/encoding_test.go:64:17: struct with 32 pointer bytes could be 24
./openapi3/loader_relative_refs_test.go:11:23: struct with 40 pointer bytes could be 32
./openapi3/loader_relative_refs_test.go:17:39: struct with 48 pointer bytes could be 40
./openapi3/operation_test.go:48:13: struct with 40 pointer bytes could be 32
./openapi3/server_test.go:64:13: struct with 40 pointer bytes could be 32

$> fieldalignment -fix ./openapi3filter
./openapi3filter/errors.go:12:19: struct with 56 pointer bytes could be 48
./openapi3filter/errors.go:47:20: struct with 40 pointer bytes could be 32
./openapi3filter/middleware.go:172:26: struct with 88 pointer bytes could be 40
./openapi3filter/middleware.go:233:28: struct with 40 pointer bytes could be 24
./openapi3filter/options.go:9:14: struct with 16 pointer bytes could be 8
./openapi3filter/req_resp_decoder.go:37:17: struct with 64 pointer bytes could be 56
./openapi3filter/validate_response_input.go:10:30: struct with 48 pointer bytes could be 40
./openapi3filter/validation_error.go:11:22: struct with 80 pointer bytes could be 64
./openapi3filter/validation_handler.go:18:24: struct with 64 pointer bytes could be 56
./openapi3filter/req_resp_decoder_test.go:70:16: struct with 128 pointer bytes could be 112
./openapi3filter/req_resp_decoder_test.go:1130:17: struct with 96 pointer bytes could be 88
./openapi3filter/validate_request_test.go:103:13: struct with 72 pointer bytes could be 64
./openapi3filter/validation_error_test.go:29:23: struct with 40 pointer bytes could be 32
./openapi3filter/validation_error_test.go:37:21: struct with 280 pointer bytes could be 256
./openapi3filter/validation_error_test.go:594:23: struct with 56 pointer bytes could be 48
./openapi3filter/validation_test.go:22:21: struct with 64 pointer bytes could be 56
./openapi3filter/validation_test.go:29:22: struct with 40 pointer bytes could be 24
./openapi3filter/validation_test.go:35:28: struct with 24 pointer bytes could be 16
./openapi3filter/validation_test.go:386:17: struct with 72 pointer bytes could be 64
./openapi3filter/validation_test.go:504:10: struct with 32 pointer bytes could be 24
./openapi3filter/middleware_test.go:179:20: struct with 16 pointer bytes could be 8
./openapi3filter/middleware_test.go:183:13: struct with 192 pointer bytes could be 184

$> fieldalignment -fix ./openapi3gen
./openapi3gen/openapi3gen.go:39:19: struct with 16 pointer bytes could be 8
./openapi3gen/openapi3gen_test.go:20:18: struct with 192 pointer bytes could be 144
./openapi3gen/openapi3gen_test.go:272:23: struct with 24 pointer bytes could be 16
./openapi3gen/openapi3gen_test.go:303:23: struct with 24 pointer bytes could be 16
./openapi3gen/openapi3gen_test.go:334:18: struct with 40 pointer bytes could be 24
./openapi3gen/openapi3gen_test.go:370:23: struct with 24 pointer bytes could be 8
./openapi3gen/simple_test.go:12:13: struct with 192 pointer bytes could be 144

$> fieldalignment -fix ./routers
./routers/types.go:22:12: struct with 64 pointer bytes could be 56

ilteoood avatar Apr 03 '22 18:04 ilteoood

This is strange, these 3 files can't be optimized because the relative tests fails:

image

ilteoood avatar Apr 03 '22 19:04 ilteoood