Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-61773

Don't use dynamic_cast in the hot path of DCP step

    XMLWordPrintable

Details

    • Untriaged
    • 0
    • Unknown
    • March-June 24

    Description

      dynamic_cast is a slow operation and shouldn't be used in the hot DCP path.

      Its currently being used in

      ConnHandler* EventuallyPersistentEngine::tryGetConnHandler(
              CookieIface& cookie) {
          auto* iface = cookie.getConnectionIface().getDcpConnHandler();
          if (iface) {
              auto* handler = dynamic_cast<ConnHandler*>(iface);
              if (handler) {
                  return handler;
              }
              throw std::logic_error(
                      "EventuallyPersistentEngine::tryGetConnHandler(): The "
                      "registered connection handler is not a ConnHandler");
          }
       
          return nullptr;
      }
      

      Which is being called every time the DCP producer calls step (which happens for every message sent over the the DCP stream).

      The "sanity check" may be nice to have to track if someone suddenly added a new conn handler class, but its not worth the runtime cost. There is currently no plans of adding a new class and I'm pretty sure this isn't the only place one would need to change the logic if one decided to add a new class.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            owend Daniel Owen
            trond Trond Norbye
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty