Skip to content

Koffi performance #3

@Koromix

Description

@Koromix

Hi,

I saw your package some time ago and it sent me into a rabbit hole when I saw how slow Koffi was on your memset benchmark. Thank you for noticing this problem :)

Part of the reason was that Koffi 2 uses external objects to represent pointers, instead of BigInt, and memset returns a pointer. So for each memset call, a V8 external object is created for the return value, and it is slow. But there are many other inefficiencies in Koffi 2 !

I will soon release Koffi 3.0, which uses BigInt pointers. But more than that, I've significantly reduced the overhead for normal synchronous calls. You can test the new version with npm install koffi@3.0.0-alpha.1 if you want.

With all the changes I've made, I get the following benchmark results on Windows with koffi@3.0.0-alpha.1:

╔════════════════════════════════════════════════════════════════╗
║                          SUMMARY                               ║
╠════════════════════════════════════════════════════════════════╣
║ ✗ abs(int32)                           2.99x slower vs koffi   ║
║ ✗ strlen(string)                       2.57x slower vs koffi   ║
║ ✗ sqrt(double)                         3.62x slower vs koffi   ║
║ ✗ GetTickCount()                       3.40x slower vs koffi   ║
║ ✗ memset(ptr,int,size)                 3.80x slower vs koffi   ║
║ ✗ sprintf(variadic)                    1.22x slower vs koffi   ║
║ ✗ struct read (2 fields)               1.20x slower vs koffi   ║
╠════════════════════════════════════════════════════════════════╣
║ Average ratio: 2.68x (koffi faster)                            ║
║ Wins: node-ctypes 0, koffi 7                                   ║
╚════════════════════════════════════════════════════════════════╝

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions