Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-850

[GH-555] Improved performance of BlobType

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      This issue is created automatically through a Github pull request on behalf of BenMorel:

      Url: https://github.com/doctrine/dbal/pull/555

      Message:

      I noticed that the `string` to `resource` conversion code in `BlobType` uses a quite inefficient technique.
      This PR improves its performance with a simple change involving the `php://temp` stream.

      Quick benchmark of the two approaches, converting a 10MB string:

      $value = str_repeat('x', 10 * 1024 * 1024);

      $t = microtime(true);
      $fp = fopen('data://text/plain;base64,' . base64_encode($value), 'r');
      printf("%.3fs\n", microtime(true) - $t);

      $t = microtime(true);
      $fp = fopen('php://temp', 'rb+');
      fwrite($fp, $value);
      fseek($fp, 0);
      printf("%.3fs\n", microtime(true) - $t);

      Results on my laptop:

      0.090s
      0.008s

      A tenfold improvement!

        Activity

        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-555] was closed:
        https://github.com/doctrine/dbal/pull/555

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-555] was closed: https://github.com/doctrine/dbal/pull/555
        Show
        Steve Müller added a comment - Fixed in commit: https://github.com/doctrine/dbal/commit/a0777077cbb8f60eaa780cd4a56644ffc5173c55

          People

          • Assignee:
            Steve Müller
            Reporter:
            Doctrine Bot
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: