-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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 aschar 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.)