Skip to content

perf: reduce closure invocation overhead in DataConverter::reconstruct() for plain objects - #10754

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:perf/dataconverter-single-closure-bind
Open

gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:perf/dataconverter-single-closure-bind

Conversation

@gr8man

@gr8man gr8man commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Description
In DataConverter::reconstruct(), plain PHP objects (non-Entity, without a static reconstruct method or closure) were hydrated by invoking a bound closure per property inside a foreach loop. For an object with 10 properties, this caused 10 closure calls per object.

This PR passes the entire array to the bound closure once, iterating properties inside the closure.

Benchmark

Microbenchmark hydrating 50,000 plain objects (10 properties each):

  • Before: 616.56 ms (10 closure calls per object)
  • After: 213.17 ms (1 closure call per object)
  • Improvement: 2.89x faster (-65.4% time, -403.39 ms)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the enhancement PRs that improve existing functionalities label Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants