Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3024

src(objectid): cleanup and simplification, perf improvement

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Performance
    • Labels:

      GitHub PR: https://github.com/mongodb/js-bson/pull/338
      I have another PR prepared that trivially speeds up the equals method a ton, but wanted to clean the surrounding code up first.


      • Since Node.js v6.9.0 is the minimum version, Buffer.from is always available. Allows removing decodeLookup stuff, poor duck-typing of 'id' (this.id.copy was used as a test for it being a buffer).
      • Indicate that 12-byte string is allowed as constructor arg.
      • Simplify logic in constructor. Performance improvement from not having to call isValid in as many cases and reordering of branches. Creating an ObjectId from a hex string is now ~19% faster.
      • Remove a hidden Buffer constructor usage (aliased as new _Buffer)
      • Add a TODO regarding an existing bug in getTimestamp. (I want to convert 12-char strings to Buffers in the ctor to fix this and clean other code up, but that would be a breaking change because it would make the constructor throw instead of toHexString. Throwing in the ctor seems preferable...)
      • Simplify createFromHexString. (This is the same as the constructor but requires the input be a hex string.)
      • Simplify logic (remove redundant and unnecessary code) in equals method.

            Assignee:
            Unassigned Unassigned
            Reporter:
            alexander.golin@mongodb.com Alexander Golin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: