Skip to content

Add cache for short JSON ascii dict keys - #120

Merged
jcrist merged 2 commits into
mainfrom
str-cache
Jun 16, 2022
Merged

jcrist merged 2 commits into
mainfrom
str-cache

Conversation

@jcrist

@jcrist jcrist commented Jun 16, 2022

Copy link
Copy Markdown
Member

This adds a cache for ascii string dict keys for the JSON decoder only.
Since most JSON objects are structured (with repeated keys), this helps
improve performance by reusing the same string key objects multiple
times. This slightly reduces performance for cases where string keys
don't repeat (cache is overhead only), but can result in up to 40%
speedup in cases where the cache is hit. Using a cached string:

  • Removes the cost of string validation and allocation
  • Reduces memory usage by reusing objects
  • Removes the need for a siphash24 call, since string hashes are cached
    on the string object itself.

The cache is cleared currently every 10 major GC passes to periodically
free up old pages and reduce fragmentation.

jcrist added 2 commits June 16, 2022 12:54
This adds a cache for ascii string dict keys for the JSON decoder only.
Since most JSON objects are structured (with repeated keys), this helps
improve performance by reusing the same string key objects multiple
times. This slightly reduces performance for cases where string keys
don't repeat (cache is overhead only), but can result in up to 40%
speedup in cases where the cache is hit. Using a cached string:

- Removes the cost of string validation and allocation
- Reduces memory usage by reusing objects
- Removes the need for a siphash24 call, since string hashes are cached
on the string object itself.

The cache is cleared currently every 10 major GC passes to periodically
free up old pages and reduce fragmentation.
@jcrist
jcrist merged commit a9c37f1 into main Jun 16, 2022
@jcrist
jcrist deleted the str-cache branch June 16, 2022 18:07
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