Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-621

[C++] Implement an "inline visitor" template that enables visitor-pattern-like code without virtual function dispatch

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.3.0
    • C++
    • None

    Description

      For performance-sensitive dynamic dispatch, the current visitor pattern may be suboptimal due to having two virtual function dispatches per invocation. For example, we might have:

      ArrayVisitor* visitor = ...;
      RETURN_NOT_OK(array->Accept(visitor));
      

      For certain types of visitors, it may be possible to create a reusable pattern like:

      template <typename VISITOR>
      Status VisitArrayInline(const Array& array, VISITOR* visitor) {
        switch(array.type_id()) {
          case UINT8:
            return visitor->Visit(static_cast<const UInt8Array&>(array));
          ...
          default:
            break;
        }
        return Status::NotImplemented("Array type not implemented");
      }
      

      It would be useful to have an understanding of how this design pattern realistically impacts performance in canonical Arrow use cases (e.g. IPC record batch loading / unloading).

      Attachments

        Activity

          People

            wesm Wes McKinney
            wesm Wes McKinney
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: