Skip to content

Use a freelist for struct types - #44

Merged
jcrist merged 2 commits into
masterfrom
struct-freelist
Jul 9, 2021
Merged

Use a freelist for struct types#44
jcrist merged 2 commits into
masterfrom
struct-freelist

Conversation

@jcrist

@jcrist jcrist commented Jul 9, 2021

Copy link
Copy Markdown
Member

This adds a freelist for "small" struct objects (currently defined as
1 <= nfields <= 10). Structs are added to the freelist during
deallocation, up to a per-size cap (currently 2000). Structs can then be
allocated from the freelist (if non-empty), skipping the cost of a
malloc.

To prevent keeping old pages around, the freelist is cleared every major
GC collection. This is done by a hook added to the module m_traverse
(since modules should persist for the lifetime of the program, they'll
usually be in the largest generation).

During high load, this leads to a measurable (4-6%) performance
improvement on deserialization.

jcrist added 2 commits July 8, 2021 23:22
This adds a freelist for "small" struct objects (currently defined as
`1 <= nfields <= 10`). Structs are added to the freelist during
deallocation, up to a per-size cap (currently 2000). Structs can then be
allocated from the freelist (if non-empty), skipping the cost of a
malloc.

To prevent keeping old pages around, the freelist is cleared every major
GC collection. This is done by a hook added to the module `m_traverse`
(since modules should persist for the lifetime of the program, they'll
usually be in the largest generation).

During high load, this leads to a measurable (4-6%) performance
improvement on deserialization.
@jcrist

jcrist commented Jul 9, 2021

Copy link
Copy Markdown
Member Author

Running the benchmark script gives:

master

- msgspec...
  dumps: 224.36 us
  loads: 688.29 us
- msgspec asarray...
  dumps: 154.70 us
  loads: 453.03 us

This PR

- msgspec...
  dumps: 222.62 us
  loads: 622.18 us
- msgspec asarray...
  dumps: 152.51 us
  loads: 435.89 us

For 10% and 4% speedups on load time respectively.

@jcrist
jcrist merged commit 6a5973e into master Jul 9, 2021
@jcrist
jcrist deleted the struct-freelist branch July 9, 2021 04:42
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.

1 participant