News for hackers. Stuff that matters.
Re:Fast Virtual Functions: Hacking the VTable for Fun and Pr... by kukkamario on Thursday March 21, 2024 @03:16PM (#39783118)
Perspective really changes when simple integer addition can take more time than allocation in a compiled language.
Re:Fast Virtual Functions: Hacking the VTable for Fun and Pr... by ninkendo on Saturday March 23, 2024 @10:53AM (#39800362)
Hmm, assuming you’re talking about heap allocation, could you elaborate? I’m curious.

[Edit: You may have meant “when simple integer addition [in a scripting language] can take more time than allocation in a compiled language”, in which case sure, I agree. I had originally interpreted your statement as saying compiled languages can do allocation faster than they can do addition…]

Allocation in most environments I’ve seen involves keeping track of a “free list”, which does some amount of pointer chasing to find a contiguous section of memory that can fulfill the request. Deallocation drops the item from the list, etc. This can result in some fragmentation, and the segments of memory managed by the free list are less likely to be in cache because they’re somewhat dispersed compared to stack memory. Some environments have multiple free lists depending on the expected size of the allocated objects, to avoid fragmentation.

How could all this be faster than a single integer addition?

Re:Fast Virtual Functions: Hacking the VTable for Fun and Pr... by LegionMammal978 on Saturday March 23, 2024 @11:41AM (#39800721)
When it's a bigint addition, as all integer additions in Python are.

Also, even when both integers are small, Python usually has to do an allocation anyway to store the result.