Skip to content

refactor(database): optimize _processForeignKeys() string allocations and loop invariants#10351

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:perf/optimize-forge-foreignkeys
Open

refactor(database): optimize _processForeignKeys() string allocations and loop invariants#10351
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:perf/optimize-forge-foreignkeys

Conversation

@gr8man

@gr8man gr8man commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description
Refactors _processForeignKeys() in Forge.php to optimize performance and reduce memory allocations:

  • Calculates invariant SQL fragments (e.g., driver checks, fkSuffix, prefixSql) once outside the main loop.
  • Caches the escaped table identifier, significantly reducing repeated calls to $this->db->escapeIdentifiers().
  • Builds the SQL constraint string locally in memory using a single sprintf() and string appending before performing a single concatenation to the $sqls array. This saves multiple intermediate array lookup and string allocations per foreign key.

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

gr8man added 2 commits June 29, 2026 23:13
Refactors _processForeignKeys() to:
- calculate invariant SQL fragments outside the loop
- cache escaped table identifier
- build SQL string locally before concatenating to the array, saving intermediate string allocations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant