Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-1172

Better BSON deserialisation with Codecs

    • 4
    • 4
    • 4
    • 100
    • Hide

      Engineer(s): Andreas Braun

      2023-09-01: Set target date to 2023-09-15

      • Performance testing and codec support in operations completed
      • Picking up lazy BSON structure support when Andreas is back from WebSummerCamp

      2023-08-18: Set target date to 2023-08-25

      • Performance tests in progress

      2023-08-04: Set target date to 2023-08-18 due to PTO

      • Implementing performance benchmarks
      • Identified bottleneck on BSON iteration, fix in review
      • Revisiting lazy BSON structures, esp. lazy BSON array implementation due to how PHP handles arrays (they are hashes)

      2023-07-21:

      • Implemented codec basics
      • Lazy BSON structures are in review
      • Codec support for operations is being finalised

      2023-07-07:

      • Started work based on earlier prototype
      • Finalised Codec interfaces
      • Started work on lazy BSONArray and BSONDocument classes in PHPLIB
      Show
      Engineer(s): Andreas Braun 2023-09-01: Set target date to 2023-09-15 Performance testing and codec support in operations completed Picking up lazy BSON structure support when Andreas is back from WebSummerCamp 2023-08-18: Set target date to 2023-08-25 Performance tests in progress 2023-08-04: Set target date to 2023-08-18 due to PTO Implementing performance benchmarks Identified bottleneck on BSON iteration, fix in review Revisiting lazy BSON structures, esp. lazy BSON array implementation due to how PHP handles arrays (they are hashes) 2023-07-21: Implemented codec basics Lazy BSON structures are in review Codec support for operations is being finalised 2023-07-07: Started work based on earlier prototype Finalised Codec interfaces Started work on lazy BSONArray and BSONDocument classes in PHPLIB

      Summary

      Provide a new mechanism to deserialise BSON into its PHP representation. Instead of relying on PHPC to deserialise BSON into a PHP representation, the library will instruct the driver to return raw BSON data (in the form of a MongoDB\BSON\Document instance) and lazily decode it as necessary.
      This last step is done through a new concept called codecs, which will replace the current BSON serialisation methods (MongoDB\BSON\Serializable and MongoDB\BSON\Unserializable). This allows separating the business logic in the PHP object representing a document from the logic necessary to encode it into BSON.

      Motivation

      Who is the affected end user?

      Users of the PHP driver

      How does this affect the end user?

      BSON deserialisation is currently done in the PHP extension with users able to customise this using the type map functionality. While this allows some flexibility when decoding BSON, the process always involves deserialising the entire BSON document, which can be very time consuming.

      How likely is it that this problem or use case will occur?

      This affects all users of the driver whenever they read data from MongoDB or write data to it.

      If the problem does occur, what are the consequences and how severe are they?

      Especially with large documents, a performance degradation can occur. Also, due to the requirement of coupling the serialisation logic with the business logic of the object, it is difficult or even impossible to create serialisation rules for third-party libraries (e.g. value objects provided by currency libraries).

      Is this issue urgent?

      Is this ticket required by a downstream team?

      The work done here can be leveraged in the Laravel integration as well as the Doctrine MongoDB ODM.

      Is this ticket only for tests?

      No

      Cast of Characters

      Engineering Lead: Andreas Braun
      Document Author: Andreas Braun
      POCers:
      Product Owner:
      Program Manager:
      Stakeholders:

      Channels & Docs

      Slack Channel

      [Scope Document|some.url]

      [Technical Design Document|some.url]

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              10 weeks