Re: Performance of ffi.new v/s malloc() arrays

  • From: Mike Pall <mikelj-1702@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 20 Feb 2017 12:24:50 +0100

Ammar Hakim wrote:

If I run it with the "useFFIAlloc" flag set to "true" the code runs about
3x faster on my Mac! This is with LJ 2.1 beta2. It seems the difference is
not so much on a Linux box, but I have not tested on Linux extensively (I
do most of my dev work on a Mac). If anyone has any ideas or perhaps can
point to something I am not doing properly, it will be great.

The code for the loop itself is nearly identical. And it's the
same speed for me (on Linux).

Since we're talking about really big arrays, the memory hierarchy
comes into play. Print out the pointer values you get and check
for aliasing wrt. cache associativity (e.g. multiples of 64K, 1MB
etc.).

Most Linux libc allocators and LuaJIT's internal allocator take
care to return big memory chunks that don't alias.

Next thing to try on your Mac would be to link against a different
malloc library. Then maybe explore huge page support. And try some
profiling with tools that show the CPU performance counters.

--Mike

Other related posts: