Skip to content

Conversation

@ovr
Copy link
Member

@ovr ovr commented Dec 15, 2025

Memory improvements:

  • QueryCache now uses a Map instead of nested objects (storage['a']['b']['c'] that could grow unbounded) for cleaner storage
  • CompilerCache now uses an LRU limit of 10k objects (i've separated global cache to from QueryCache). No more memory leaks.

Performance optimization:

  • New computeCacheKey() function is ~3x faster than JSON.stringify for common cases
  • Uses V8's ConsString optimization (string concatenation builds a tree of segments instead of copying)
  • Strings and numbers are concatenated directly; only objects fall back to JSON.stringify

@github-actions github-actions bot added the javascript Pull requests that update Javascript code label Dec 15, 2025
- Replace nested object structure with Map<string, any>
- Use JSON.stringify for composite keys
- Consistent approach with CompilerCache
* @returns Returns the result of executing a function (Either call a function or take a value from the cache)
*/
public cache(key: any[], fn: Function): any {
let keyHolder = this.storage;
Copy link
Member Author

@ovr ovr Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  // For key ['a', 'b', 'c']:
  // storage['a'] = {}
  // storage['a']['b'] = {}
  // storage['a']['b']['c'] = fn()

I don't know the reason (I assume, string interning) for writing such a nested cache, but I am certain that it's better to rewrite it. I've done fastComputeCacheKey and tested that it's using ConsString

- Add computeCacheKey function using V8 ConsString optimization
- String concatenation (+=) is ~3x faster than JSON.stringify
- Handle string/number directly, fallback to JSON.stringify for objects
- Support both array keys and unknown key types
Copy link
Member

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@ovr ovr marked this pull request as ready for review December 15, 2025 17:16
@ovr ovr requested a review from a team as a code owner December 15, 2025 17:16
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.12%. Comparing base (5df4280) to head (f2a453a).
⚠️ Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
...s/cubejs-schema-compiler/src/adapter/QueryCache.ts 82.60% 3 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (5df4280) and HEAD (f2a453a). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (5df4280) HEAD (f2a453a)
cubesql 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #10247       +/-   ##
===========================================
- Coverage   83.25%   55.12%   -28.14%     
===========================================
  Files         247      221       -26     
  Lines       74259    17128    -57131     
  Branches        0     3505     +3505     
===========================================
- Hits        61826     9442    -52384     
+ Misses      12433     7187     -5246     
- Partials        0      499      +499     
Flag Coverage Δ
cube-backend 55.12% <88.57%> (?)
cubesql ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ovr ovr requested review from a team as code owners December 15, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data source driver javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants