Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4007

Micro-optimization of TTransport.py

    XMLWordPrintableJSON

Details

    Description

      Method readAll(self, sz) in class TTransportBase in TTransport.py can be optimized to only call len(chunk) once. It currently calls len(chunk) twice, i.e.

      def readAll(self, sz):
          buff = b''
          have = 0
          while (have < sz):
              chunk = self.read(sz - have)     
              have += len(chunk)
      
              buff += chunk
      
              if len(chunk) == 0:
                  raise EOFError()
      
          return buff
      

      That results in two method invocations to len(chunk) but it can be reduced to one method invocation to len(chunk). Depending on the amount of data being read, the extra len(chunk) method invocations can add up to slightly slower performance.

      Attachments

        Issue Links

          Activity

            People

              jking3 James E. King III
              ndjensen Nathan Jensen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: