Performance of printing a type name

Is this expected, or is this a bug? Printing Val(:hello_world) is ~1000 times slower than printing :hello_world, and I imagine this affects things like printing stack traces with complicated types.

julia> @benchmark string(Val(:a))
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  311.461 μs …  1.826 ms  ┊ GC (min … max): 0.00% … 80.96%
 Time  (median):     321.411 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   323.074 μs ± 32.385 μs  ┊ GC (mean ± σ):  0.22% ±  1.87%

                 ▁▃▄▆█▇▆▇▇▇▄▄▅▄▅▃▄▂▁
  ▂▂▂▂▂▃▃▄▄▄▅▅▅▆▆████████████████████▆▆▆▅▅▄▄▄▃▃▃▃▃▃▃▂▂▂▂▂▂▂▂▁▂ ▅
  311 μs          Histogram: frequency by time          336 μs <

 Memory estimate: 26.73 KiB, allocs estimate: 25.

julia> @benchmark string(:a)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  14.309 ns … 778.920 ns  ┊ GC (min … max): 0.00% … 95.49%
 Time  (median):     16.483 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   17.907 ns ±  16.759 ns  ┊ GC (mean ± σ):  2.03% ±  2.14%

        ▁ █
  ▂▁▂▂▃▆███▇▆▅▅▄▄▄▃▃▄▆▃▃▃▄▃▂▂▂▂▂▂▃▃▃▄▄▄▄▄▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  14.3 ns         Histogram: frequency by time         25.6 ns <

 Memory estimate: 24 bytes, allocs estimate: 1.

The output of string(Val(:a)) is "Val{:a}()" and not “a”. So it generates a longer string than if you convert a symbol to a string.

The usage of value of described here Types · The Julia Language . Typically you would use multiple dispatch to enforce to compile the function you use for each new value.
For example:

tostring(::Val{x}) where {x} = string(x)

and then tostring(Val(:a)) is basically resolved at compile time.

(Of course, for this simple conversation example, it is very likely that there is no need to use Val. As noted in the linked documentation.)

I understand that, but the difference is between 16ns and 321,000ns. That’s much more than due to generating a slightly longer, though still quite short, string.

print(:a) doesn’t have to generate a string at all — a Symbol in Julia is just an interned string, so Julia already has the text representation. Whereas for printing an arbitrary type it needs to do introspection.