Skip to content

sql: minimize TableDescriptor copies/re-allocation/serialization #74352

@nvb

Description

@nvb

descpb.TableDescriptor structs are 1104 bytes large (ignoring internal references). tabledesc.immutable structs embed a descpb.TableDescriptor and are 1168 byte large. Due to this size, we should strive to minimize the number of times that we copy, re-allocate, or serialize these structs on the hot path of query processing.

@ajwerner, a man ahead of his time, has TODOs that allude to this:

// TODO(ajwerner): The need to construct an immutable here
// indicates that we're probably doing this wrong. Instead we should be
// just setting the ID and Version in the spec or something like that and
// retrieving the hydrated immutable from cache.
table := spec.BuildTableDescriptor()

In recent experimentation, I've observed these copies in CPU and heap profiles. On a 100% read workload, immutable allocations are not only the second largest source of heap allocations (by size), but they also appear prominently in CPU profiles. For instance, in kv100 (which is CPU-bound), TableReaderSpec.BuildTableDescriptor is responsible for 1.33% of all CPU utilization.

Screen Shot 2021-12-30 at 6 56 53 PM

Jira issue: CRDB-12042

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-executionRelating to SQL execution.C-performancePerf of queries or internals. Solution not expected to change functional behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions