Skip to content

Performance#10

Merged
CAFernandes merged 10 commits intomainfrom
performance
Jul 6, 2025
Merged

Performance#10
CAFernandes merged 10 commits intomainfrom
performance

Conversation

@CAFernandes
Copy link
Owner

Pull Request Template

📋 Descrição

Descreva resumidamente as mudanças feitas neste PR.

🎯 Tipo de Mudança

  • 🐛 Bug fix (mudança que corrige um bug)
  • ✨ Nova feature (mudança que adiciona funcionalidade)
  • 💥 Breaking change (mudança que causa incompatibilidade)
  • 📚 Documentação (mudanças apenas na documentação)
  • 🧹 Refactoring (mudanças que não corrigem bug nem adicionam feature)
  • ⚡ Performance (mudanças que melhoram a performance)
  • 🧪 Testes (adição ou correção de testes)

🧪 Como foi testado?

Descreva os testes que você executou para verificar suas mudanças.

  • Testes unitários passando
  • Testes funcionais passando
  • Testado manualmente
  • Exemplos funcionando

📝 Checklist

  • Meu código segue as diretrizes de estilo do projeto
  • Eu fiz uma auto-revisão do meu código
  • Comentei meu código, especialmente em partes difíceis de entender
  • Fiz mudanças correspondentes na documentação
  • Minhas mudanças não geram novos warnings
  • Adicionei testes que provam que minha correção é eficaz ou que minha feature funciona
  • Testes unitários novos e existentes passam localmente com minhas mudanças

CAFernandes and others added 2 commits July 6, 2025 12:25
- Created detailed database performance analysis comparing MySQL, PostgreSQL, MariaDB and SQLite
- Added benchmark results showing throughput and latency for different database operations
- Documented PDO configuration and optimization strategies for each database
- Included real-world performance metrics with Express PHP framework overhead analysis
- Updated documentation indices to include database performance section
- Added code examples demonstrating PDO usage with prepared statements

Key insights:
- SQLite shows best performance for small/medium applications
- MariaDB outperforms MySQL in most scenarios
- PostgreSQL excels at complex queries
- Connection pooling provides 40%+ improvement for relational databases
- Express PHP adds minimal overhead (<0.2ms average)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…s PHP v2.1.3

- Introduced PERFORMANCE_SUMMARY.md for detailed performance metrics.
- Updated existing PERFORMANCE_SUMMARY.md with new test results and metrics.
- Created run_all_benchmarks.php to automate benchmark execution and reporting.
- Added docker-compose.benchmark.yml for a complete benchmarking environment setup.
- Developed PERFORMANCE_COMPARISON.md to track performance evolution across versions.
- Generated PERFORMANCE_REPORT_v2.1.3.md for a detailed analysis of v2.1.3 performance.
- Updated README.md in benchmarks to reflect the latest performance results.
- Revised FRAMEWORK_OVERVIEW_v2.1.3.md to include current performance metrics.
- Implemented PDOConnection.php for database interactions in benchmarks.
- Added DatabaseException.php for handling database-related errors.
@CAFernandes CAFernandes self-assigned this Jul 6, 2025
Copilot AI review requested due to automatic review settings July 6, 2025 15:33

This comment was marked as outdated.

CAFernandes and others added 3 commits July 6, 2025 12:36
- Fix getInstance() to properly handle null instance case by throwing DatabaseException
- Fix lastInsertId() to handle false return value from PDO
- Add proper exception handling and type safety
- Maintains backward compatibility while ensuring type correctness

This resolves the PHPStan Level 9 errors reported in GitHub Actions.
- Move PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to driver-specific configuration
- Ensure common PDO options are applied to all drivers
- Add comprehensive unit tests for driver-specific configurations
- Prevent errors when using PostgreSQL, SQLite, or other non-MySQL drivers

This fixes potential errors when using PDOConnection with non-MySQL databases.
- Check for PDO::MYSQL_ATTR_USE_BUFFERED_QUERY and PDO::MYSQL_ATTR_COMPRESS constants before use
- Fix array merge to preserve numeric PDO constant keys
- Update tests to skip MySQL-specific assertions when extension is not available
- Fix PSR-12 compliance issues (trailing whitespace, EOF newlines)
- Ensure PDOConnection works with SQLite when MySQL extension is not present

This allows the framework to work properly in environments where only specific PDO drivers are installed.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CAFernandes CAFernandes requested a review from Copilot July 6, 2025 16:01

This comment was marked as outdated.

- Remove appended PDO error message from connection failure to match test
- Test expects exact message 'Database connection failed' without details
- The previous exception is still passed for debugging via stack trace

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CAFernandes CAFernandes requested a review from Copilot July 6, 2025 16:08

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CAFernandes CAFernandes requested a review from Copilot July 6, 2025 16:11

This comment was marked as outdated.

CAFernandes and others added 3 commits July 6, 2025 13:17
- Replace array union operator (+) with array_replace() for clarity
- array_replace() explicitly shows user options take precedence
- More intuitive behavior: defaults are replaced by user options
- Preserves numeric PDO constant keys correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Reset both instance and config in close() method
- Prevents stale configuration from persisting after connection close
- Add test to verify configuration is properly cleared
- Ensures clean state for subsequent connections

This prevents potential bugs where old configuration could affect new connections
after calling close().

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add support for 'collation' configuration key in PDO options
- Set collation via PDO::MYSQL_ATTR_INIT_COMMAND for MySQL/MariaDB
- Add proper checks for MySQL extension constants availability
- Create comprehensive tests for collation setting functionality
- Handle cases where MySQL PDO extension is not available

The 'collation' configuration key was previously unused. This change
ensures it's properly applied when connecting to MySQL/MariaDB databases
via the SET NAMES command with COLLATE clause.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CAFernandes CAFernandes requested a review from Copilot July 6, 2025 16:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR delivers a new singleton-based PDOConnection manager (with DatabaseException), full PHPUnit coverage for its configuration/connect/query methods, and a major update of performance documentation and Docker-based benchmarking setup targeting v2.1.3.

  • Added src/Database/PDOConnection.php and src/Exceptions/DatabaseException.php for unified PDO handling.
  • Introduced comprehensive PHPUnit tests in tests/Database/PDOConnectionTest.php.
  • Updated release notes, performance metrics, benchmark docs, and Docker configurations for version 2.1.3.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Database/PDOConnectionTest.php Adds unit tests for driver-specific and common PDO configuration.
src/Exceptions/DatabaseException.php Defines a custom exception for database errors.
src/Database/PDOConnection.php Implements singleton PDO manager with driver options and utilities.
docs/releases/README.md Bumps version and last-updated date for v2.1.3.
docs/performance/* Refreshes performance metrics, comparison tables, and reports.
docker-compose.benchmark.yml & Dockerfile.benchmark Sets up standardized Docker benchmarking environment and scripts.
Comments suppressed due to low confidence (4)

docs/releases/FRAMEWORK_OVERVIEW_v2.1.3.md:40

  • The response creation metric here (2.27M ops/sec) doesn’t match the 2.58M ops/sec reported in PERFORMANCE_REPORT_v2.1.3; please reconcile these values for consistency.
- **2.27M ops/sec** - Response Object Creation

docs/performance/PERFORMANCE_COMPARISON.md:11

  • The improvement column shows "+14x" for v2.1.3 vs v2.0.1 but the ops/s values suggest a different ratio; please verify and correct the improvement percentage.
| **Response Creation** | 2.58M ops/s | 2.69M ops/s | 24M ops/s* | 18M ops/s | +14x |

src/Database/PDOConnection.php:256

  • There’s no unit test covering getStats()—consider adding a test to verify that returned driver, version, and status attributes are correct.
    public static function getStats(): array

src/Exceptions/DatabaseException.php:16

  • [nitpick] The constructor only calls the parent without modification—consider removing it for brevity, relying on the inherited constructor behavior.
    public function __construct(string $message = "", int $code = 0, ?Exception $previous = null)

@CAFernandes CAFernandes merged commit e42382c into main Jul 6, 2025
5 checks passed
@CAFernandes CAFernandes deleted the performance branch July 6, 2025 16:30
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.

2 participants