On Wed, Aug 23, 2023 at 7:30â¯AM Chris Prather <chris@prather.org> wrote: > "It depends." I don't think the types themselves (or numbers known at > compile time) are the problem. > > I'm not an expert here and I'm seriously hoping someone steps up to > call me an idiot and wrong but as best I can tell the performance hit > isn't entirely the assertion check itself, it's the slow down on > _everything_ that simply having the assertion causes. As was mentioned > in this thread there are only so many ways to attach extra behavior to > a variable in Perl and we've spent since 1995 (or possibly 1985) > optimizing the common case of having no extra behavior. The minute you > add a type annotation we need to include a way to look up the > assertion check, which means we no longer have a "simple" SV (or AV or > HV) and all the optimized code isn't used. > We have a distinction between get and set magic, so for scalars we can actually do efficient shallow type checks, see Magic::Check on CPAN for an implementation of this. Arrays and hashes are still screwed though, and we made some API choices in the past that make fixing it now more difficult than one would hope. > Realistically all I've seen evidence for in initially from _either_ > Oshun or Perl::Types is[2]: > > * (type checking) > * documentation of code intent > * potential for polymorphism > Agreed.Thread Previous | Thread Next