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

improvement for compiler-generated python for 'None' object comparisons

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.7
    • Python - Compiler
    • None
    • Patch Available

    Description

      The python code generator produces several python statements, especially the write() methods' per-field code, that compares something to None using '!= None', when it is more efficient to use the 'is not None' expression.

      From what I understand, in python it's almost always true that (x != None) == (x is not None), but the actual implementation and intent is very different. The '!= None' comparison does a by-value comparison that does much more work than an object identity 'is not None' comparison does.

      The actual performance impact isn't much, but I benchmarked the performance of 'x is not None' to 'x != None' and got some interesting results. In python 2.4, 2.7 and 3.1, it's about 2-3 times as fast to use 'is not None' over '!= None'.

      I'll attach a patch to switch to 'is not None', and attach a simple benchmark test script exercising 'is not None' vs. '!= None' and post the performance measurements to this ticket.

      These URLs are somewhat relevant about this specific issue in general:

      Attachments

        1. test_isnotnone.py
          0.6 kB
          Will Pierce
        2. THRIFT-1107.compiler_generate_py_is_not_none.patch
          2 kB
          Will Pierce

        Activity

          People

            willp Will Pierce
            willp Will Pierce
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: