longlene / cl-raylib

Common Lisp binding of raylib
MIT License
145 stars 21 forks source link

Add `expand-into-foreign-memory` and `expand-from-foreign` for performance consideration #38

Closed bohonghuang closed 1 year ago

bohonghuang commented 1 year ago

Hi! Recently I found it too expensive to invoke generic functions in every single frame via translate-from-foreign and translate-into-foreign-memory, especially on ECL, which spends much more time to call a generic function than the ordinary one.

CFFI provides a more efficient way to convert FFI type by optimizing out the function calls at compile-time so that the implementations could avoid generic method dispatching and some implementations like SBCL can also avoid SAP to pointer conversion to improve the performance of the game.

So I wrote 2 macros that generate both the translation and expansion function in substitution of defmethod translate-into-foreign-memory and defmethod translate-from-foreign, in hopes they can reduce the FFI overhead of cl-raylib.

longlene commented 1 year ago

@bohonghuang Thanks, looks great!