Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 128591e637758eb30386fdad64d648ee08535581
      
https://github.com/WebKit/WebKit/commit/128591e637758eb30386fdad64d648ee08535581
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-04-16 (Thu, 16 Apr 2026)

  Changed paths:
    A JSTests/microbenchmarks/json-parse-repeated-short-strings.js
    A JSTests/stress/json-parse-jsstring-cache-coherence.js
    M Source/JavaScriptCore/heap/Heap.cpp
    M Source/JavaScriptCore/runtime/JSONAtomStringCache.h
    M Source/JavaScriptCore/runtime/JSONAtomStringCacheInlines.h
    M Source/JavaScriptCore/runtime/LiteralParser.cpp

  Log Message:
  -----------
  [JSC] Cache `JSString` cells for short `JSON.parse` string values
https://bugs.webkit.org/show_bug.cgi?id=312224

Reviewed by Yusuke Suzuki.

JSONAtomStringCache caches AtomStringImpl for object keys, but string
*values* still allocated a fresh JSString cell on every occurrence via
jsString(), even for repeated short strings like "type":"text" or
enum-style arrays.

Add a parallel std::array<JSString*, 256> m_jsStrings keyed by the same
slot index. makeJSString() returns the cached cell on a buffer hit;
makeIdentifier() nulls the parallel entry on slot eviction to keep them
coherent. The array is cleared in Heap::finalize() alongside the other
raw-pointer string caches, so no visiting is needed.

The cache range stays at len<=10 to avoid AtomString table churn on
payloads with many unique medium-length values (todomvc-style).

                                           TipOfTree                  Patched

json-parse-repeated-short-strings       25.6922+-0.1853     ^     
17.1671+-0.4399        ^ definitely 1.4966x faster

* JSTests/microbenchmarks/json-parse-repeated-short-strings.js: Added.
* JSTests/stress/json-parse-jsstring-cache-coherence.js: Added.
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::finalize): Clear m_jsStrings on every collection.
* Source/JavaScriptCore/runtime/JSONAtomStringCache.h:
Add m_jsStrings parallel array, cacheIndex() helper, clearJSStrings().
* Source/JavaScriptCore/runtime/JSONAtomStringCacheInlines.h:
(JSC::JSONAtomStringCache::makeIdentifier): Null m_jsStrings[index] on
slot eviction.
(JSC::JSONAtomStringCache::makeJSString): Added.
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::LiteralParser::makeJSString): Delegate to the new cache API.

Canonical link: https://commits.webkit.org/311426@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to