+ All Categories
Home > Technology > PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

Date post: 18-Jul-2015
Category:
Upload: pharo
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
16
FFI The good, the bad and the ugly
Transcript
Page 1: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

FFIThe good, the bad and the ugly

Page 2: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

Esteban Lorenzano(The Pharo firefighter)

Page 3: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

Several options, none of them very clear.

Current status of FFI:

A mess :(

Page 4: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

Three options: FFI, AlienFFI, NB-FFI

Page 5: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

FFI

Basic types and not much more

you can declare your own types (but nobody knows how, anyway)

No callbacks

There is a version of Eliot with callback support, but still not integrated into Pharo.

Page 6: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

FFI Characteristics

Pros

Simple

Cons

No callbacks (yet)

cdecl/apicall, module lookup

Page 7: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

AlienFFI

Object per method

GC of external memory allocations

Callbacks

Uses same primitives as FFI

Page 8: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

AlienFFI CharacteristicsPros

Object-oriented approach

Powerful

Nice callback implementation

Cons

More complex to use than plain FFI

Abandoned to a enhanced version of FFI (It should be considered legacy)

A bit slower

Page 9: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

NativeBoost FFI

Primitive call + binary code generation magic

Nice function call and type definition

Callbacks (though slower than Alien)

Uses assembly

Page 10: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

NB-FFI CharacteristicsPros

all-in-image approach

nice syntax declaration

fast

Cons

no platform independence (no ARM, no x86_64, etc.)

each new platform needs a new ASMJIT

different assembly knowledge (and well… assembly knowledge in general)

VirtualCPU can help here, but you still need to know the platform architecture

Page 11: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

How to fix the mess?We need ONE solution that works in all cases.

Sadly, NativeBoost requires a lot of effort that we cannot spend on it.

Happily, there is an existing FFI implementation, maintained by Eliot, that we can use.

And we can take parts from NativeBoost too! (like the syntax declaration)

Page 12: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

WIP

NB-FFI to FFI

ThreadFFI

uFFI

Page 13: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

WIP: NB-FFI to FFIReplaces ASM generated part with plain FFI primitive calls.

Portable (to ARM, x86_64, etc.)

No executable memory (can be used in scenaries like iPhone or with security constraints)

No need to know assembly to maintain it (yes, that’s a pro for me ;)

ASMJIT will be pluggable and still usable

Page 14: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

WIP: ThreadFFI

It will allow us to execute expensive foreign calls (i.e. SQL queries) in a separate native thread, and callback the system when finished.

Page 15: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

WIP: uFFI

Specific bytecodes (pointer allocation, primitive types, function calling)

Fast due direct memory manipulation and Cog JIT

Common interface for different backends (it will use NB syntax, too)

Page 16: PharoDAYS 2015: FFI - The good, the bad and the ugly by Esteban Lorenzano

Summary

One FFI that will work on all platforms is arriving (it will be in Pharo 4 or early Pharo 5)

Threaded FFI will come soon after

uFFI, with important enhancements will arrive some time later


Recommended