cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.19k stars 3.82k forks source link

sql: make memo.IsStale more efficient (~1.5% cpu) #105867

Open nvanbenschoten opened 1 year ago

nvanbenschoten commented 1 year ago

In a high-throughput, write-heavy workload (kv0/2kb), we see that 11.1% of heap allocations come from under a call to memo.(*Memo).IsStale.

This feels very expensive. A reading of the code reveals that many of these allocations come from:

Screenshot 2023-06-30 at 2 21 02 AM Screenshot 2023-06-30 at 2 23 10 AM

heap_profile.pb.gz

This code is on the hot path of query execution, so it deserves to be scrutinized for performance inefficiencies. Can we remove any of these heap allocations?

Jira issue: CRDB-29240

msirek commented 1 year ago

I reduced some of the heap allocations here, but kv0/2KB performance strangely decreased.

mgartner commented 8 months ago

In another real-world workload, I've observed memo.IsStale be responsible for 2.4% of CPU time:

image

And 3.4% of allocations:

image

It seems like this is rather expensive just to merely determine if a memo can be reused or not.