Skip to content

Restructured structs to save on memory#26

Merged
gboncoffee merged 1 commit into
gboncoffee:masterfrom
PBnJK:struct_reorder
Sep 12, 2024
Merged

Restructured structs to save on memory#26
gboncoffee merged 1 commit into
gboncoffee:masterfrom
PBnJK:struct_reorder

Conversation

@PBnJK

@PBnJK PBnJK commented Sep 12, 2024

Copy link
Copy Markdown
Contributor

In Go, structs are stored in memory "as-is", that is, in the order that they are written. Due to padding, this ends up leaving a bit of memory unused. It is possible (and pretty easy) to re-organize structs so as to optimize them for memory usage.

This is a pretty small PR that just optimizes some of the structs. It may be undesirable for aesthetic reasons, but in my opinion it's a pretty painless improvement.

Here is the data, if you're interested (obtained via the go lsp):

Struct Old size (bytes New size (bytes)
Token 32 16
DebuggerToken 72 48
ResolvedToken 64 40
Instruction 40 32
Breakpoint 24 16

@gboncoffee

Copy link
Copy Markdown
Owner

Great catch. Thanks for the contribution!

@gboncoffee
gboncoffee merged commit 9723818 into gboncoffee:master Sep 12, 2024
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