Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Native Modules

PetaPerl does not support XS (C extensions). Instead, performance-critical CPAN modules are reimplemented natively in Rust. These “native modules” provide the same Perl-level API as their XS counterparts but integrate directly with PetaPerl’s runtime — enabling JIT compilation, auto-parallelization, and zero FFI overhead.

How It Works

When you write use List::Util qw(sum min max), PetaPerl’s module loader detects that List::Util has a native implementation and registers Rust function pointers directly. There is no compilation step, no .so loading, and no XS glue code.

Native functions are dispatched via NativeFn — a direct function pointer with O(1) call overhead, identical to built-in operators.

Available Native Modules

Core Utilities

ModuleFunctionsNotes
Scalar::Utilblessed, reftype, refaddr, weaken, isweak, looks_like_number, …Full API
List::Utilsum, min, max, first, any, all, none, reduce, …MULTICALL optimized
Sub::Utilsubname, set_subname
Hash::Utillock_keys, lock_hash, …

Digest / Crypto

ModuleFunctionsNotes
Digest::MD5md5, md5_hex, md5_base64, OO interfaceFull API
Digest::SHAsha1, sha256, sha512, OO interfaceFull API
MIME::Base64encode_base64, decode_base64
MIME::QuotedPrintencode_qp, decode_qp

File / System

ModuleFunctionsNotes
File::Basenamebasename, dirname, fileparse
File::Copycopy, move
File::Findfind, finddepth
File::Globbsd_glob
File::Pathmake_path, remove_tree
File::Speccatdir, catfile, rel2abs, …
File::Temptempfile, tempdirOO + functional
File::statstat (OO)
Cwdcwd, getcwd, abs_path
Sys::Hostnamehostname

I/O

ModuleFunctionsNotes
IO::FileOO file handle
IO::HandleOO handle base
IO::DirOO directory handle
IO::PipeOO pipe handle
IO::Selectselect wrapper
IO::SocketOO socket handle
IO::Seekableseek/tell mixin
FileHandleLegacy OO handle
Socketsocket primitives

Data / Encoding

ModuleFunctionsNotes
Data::DumperDumper
Storablefreeze, thaw, nstore, retrieve
Encodeencode, decode, find_encoding
JSON::PPencode_json, decode_jsonVia Pure Perl

Numeric / Math

ModuleFunctionsNotes
POSIXfloor, ceil, fmod, strtod, strftime, …Subset
Math::GMPArbitrary precision integersVia Peta::FFI::GMP

Build / Config

ModuleFunctionsNotes
Config%Config hashBuild configuration
FcntlO_RDONLY, O_WRONLY, …Constants auto-loaded
ErrnoENOENT, EACCES, …Constants auto-loaded

Introspection

ModuleFunctionsNotes
BCompiler backend introspectionMinimal
PadWalkerpeek_my, peek_our
mroget_linear_isa, set_mro
versionVersion object handlingFull OO API

Performance

Native modules run at the same speed as built-in operators since they share the same dispatch mechanism. For block-taking functions (first, any, all, reduce), PetaPerl uses MULTICALL optimization to avoid per-element subroutine call overhead.

Benchmarks (vs perl5 with XS):

FunctionPetaPerl nativeperl5 XSRatio
List::Util::sum1.7x fasterbaseline
List::Util::min/max2.9x fasterbaseline
List::Util::first~1xbaselineMULTICALL parity

Adding Native Modules

See Documentation Pipeline for how native module documentation is extracted from Rust source.