When should we use `@nospecialize`?

question

#1

The manual is sketchy about the use of @nospecialize (maybe it is still WIP?). I gather it is a necessary optimisation to avoid overburdening the dispatch tables. Is the end user advised to use this macro in some specific circumstance or coding pattern?


#2

You can use it when a function is called multiple times with different argument types, compiling that function is expensive but specialising on argument types does not have a significant impact on run-time performance.

For an example in the wild: https://github.com/ZacLN/CSTParser.jl/blob/20b6eac1ec7db62ced97eadb09f0d4e9653db97a/src/CSTParser.jl#L178 (::ANY is the old @nospecialize).