Skip to content

runtime::Printer has a scratch field that is ~never used #6469

@steven-johnson

Description

@steven-johnson

The runtime Printer has a scratch field that (presumably) is meant to avoid using malloc() for small print jobs, but in practice, it appears to ~never be used:

  • The length of scratch is (theoretically) a template parameter, which defaults to 1024
  • ...but scratch is actually declared as char scratch[length <= 256 ? length : 1];, so any length of > 256 becomes just 1 (which in practice means "always use malloc")
  • The places in runtime that override the default are:
    • profiler.cpp (which happens to also end up passing 1024)
    • tracing.cpp (which passes 4096)
    • opencl.cpp (16384)
    • d3d12compute.cpp (64k)
    • d3d12compute.cpp (16)
    • d3d12compute.cpp (256)

So basically, there are only two places (in d3d12compute) that are ever using this field.

The whole thing looks wonky to me -- my guess is that length was a straight passthrough in the past, but got limited this way due to stack-size issues on some architecture, and the ramifications never thought thru.

Anyway, this is an ugly wart that should really be resolved somehow, either by removing scratch entirely (since it's rarely used currently), or by deciding that a 1024-byte sized stack scratch is OK after all, or by deciding that 256-byte scratch is adequate for most things, or... something else.

(Note that d3d12compute.cpp has a StackPrinter class that attempts to make use of this, but the class is unused and should be removed.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions