LuaJIT SHA1

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Mon, 18 Jun 2012 14:28:49 +0000

Looking at the sha1 code briefly, I'm sure you could speed things up 
significantly with a few small changes. Probably the biggest thing you could do 
is implement based on a straight buffer instead of relying on Lua strings in 
any way. For example, in your test case: repeat
   rsize = ffi.C.read(0, buf, bufsize)
   sha1.update(hash, ffi.string(buf, rsize))
until rsize < 1
At the very least, ffi.string is going to do some hashing, andcomparing as it 
tries to intern your buffer into a lua string.At the very worst, it's going to 
do a memcpy on your buffer,which I'm sure you don't want in this case. Then, 
within your implementation, you do some string concatstuff: function 
update(hash, data)
   if not data then return end   hash[6] = hash[6] + #data
   data = hash[7]..data ...      if pad == 64 then pad = 0 end
      data = data.."\128"..string.rep("\0", pad)..len
Again, in each of these cases, any time you use '..', you'regoing to create a 
new string, with the attendant copyingof buffers. I did the same thing with my 
initial implementation.  Ifyou can eliminate these cases, you'll probably get 
much closer to the speed of a typical 'C' implementation. -- William

===============================

- Shaping clay is easier than digging it out of the ground.
 > Date: Mon, 18 Jun 2012 08:29:55 -0400
> From: chris@xxxxxxxxxx
> To: luajit@xxxxxxxxxxxxx
> Subject: Re: Projects using LuaJIT ?
> 
> On 06/18/2012 07:38 AM, Patrick Masotta wrote:
> > I’ve been there, there are 3 projects??That’s all the available LuaJIT
> > codebase??
> 
> The ufo project has a bunch of FFI bindings. Specifically check out the 
> "ffi" directory.
> 
> https://github.com/malkia/ufo
> 
> My sha1 library uses LuaJIT but it's not really tuned directly for 
> LuaJIT.  In fact I would appreciate any help increasing the performance 
> if anyone knows of LuaJIT specific tweaks.
> 
> http://luadev.com
> 
> -- 
> Chris
> 
                                          

Other related posts: