feat: static property descriptors, zero heap allocation#720
Merged
ptondereau merged 1 commit intoextphprs:masterfrom Apr 14, 2026
Merged
Conversation
Member
Author
|
#310 for references |
Coverage Report for CI Build 24395157578Coverage increased (+0.4%) to 66.276%Details
Uncovered Changes
Coverage Regressions12 previously-covered lines in 6 files lost coverage.
Coverage Stats
💛 - Coveralls |
3611e36 to
d239175
Compare
…ap allocations Previously, each PHP class property required boxing closures (Box<dyn Fn>) and building a HashMap at runtime. This happened once per class but was unnecessary since all property metadata is known at compile time. Now the macros generate plain function pointers and static arrays that live entirely in read-only memory. Property lookup uses a simple linear scan over two small slices (field props, then getter/setter props), which is faster than hashing for the typical class size (< 20 properties). This removes the Property enum, Prop trait, and PropertyInfo struct, replacing them with a single PropertyDescriptor<T> that holds: - fn(&T, &mut Zval) -> PhpResult for getters - fn(&mut T, &Zval) -> PhpResult for setters - visibility flags, type info, docs Also adds callgrind-based property read/write benchmarks. Closes extphprs#70
d239175 to
32d2c43
Compare
Open
Merged
paragonie-security
added a commit
to paragonie/ext-pqcrypto
that referenced
this pull request
Apr 14, 2026
The upstream fix extphprs/ext-php-rs#720 should improve performance significantly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #70
The property system used to heap-allocate closures (
Box<dyn Fn>) and aHashMapfor every PHP class at runtime. All of this metadata is known at compile time, so there's no reason for it to live on the heap.This replaces the whole thing with static function pointers and compile-time arrays. Property lookup becomes a linear scan over two small slices (field props first, then getter/setter props), which beats hashing for the typical class size.
What changed:
PropertyDescriptor<T>type withfn(&T, &mut Zval)/fn(&mut T, &Zval)pointersClassMetadataholds&'static [PropertyDescriptor<T>]instead ofOnceCell<HashMap<...>>Propertyenum,Proptrait,PropertyInfostruct, and all the boxing machineryBenchmark results (callgrind, 100k iterations x 4 properties):
Cold-start (single access) is 3.7-4.2x faster due to no heap allocation on first use.
Breaking changes for anyone manually implementing
RegisteredClassorPhpClassImpl(rare, macros handle this).get_properties()is gone from the trait.ClassMetadata::new()now takes&'static [PropertyDescriptor<T>]. TheProperty/Prop/PropertyInfotypes no longer exist.Net diff: -204 lines.
Checklist