Skip to content

Fix Issue #35: hoist Config Struct to constant to avoid per-call allocation#36

Open
obsidiannnn wants to merge 1 commit intolow-rb:mainfrom
obsidiannnn:fix/config-struct-allocation
Open

Fix Issue #35: hoist Config Struct to constant to avoid per-call allocation#36
obsidiannnn wants to merge 1 commit intolow-rb:mainfrom
obsidiannnn:fix/config-struct-allocation

Conversation

@obsidiannnn
Copy link
Copy Markdown
Contributor

Fixes #35

Change

Hoisted Struct.new out of the config method body into a constant
so the anonymous Struct class is allocated once at load time rather
than on every call to LowType.config.

Before

Every LowType.config call allocated and discarded a new Struct class.

After

Struct class is created once. @config ||= memoizes the instance as before.

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.

Struct.new in LowType.config allocates a new anonymous class on every call

1 participant