Hacker News new | past | comments | ask | show | jobs | submit login

the post goes in detail.

Essentially, imagine you have custom routines for your ints and floats and your language doesn't support generics. You'll have a code like this

  if type is INT:
    answer = optimizedRoutineForInt();
  else type is FLOAT:
    answer = optimizedRoutineForFloat();
This happens at run-time. There's an overhead.

With generics, there's zero overhead. Your code will look something like

  answer = optimizedRoutine<Type>();
and if optimizedRoutine<Float> can be inlined at this site, there are no conditions or jumps in the code.

The post goes in detail about how for sorting, this sort of comparison function is called so frequently it has a massive impact on performance




..this comparison function of sort..




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: