turbaszek commented on pull request #8805:
URL: https://github.com/apache/airflow/pull/8805#issuecomment-636334773


   I did some simple test:
   ```python
   from datetime import datetime
   
   from airflow import DAG
   from airflow.operators.dummy_operator import DummyOperator
   from airflow.utils.decorators import apply_defaults
   from scripts.perf.perf_kit import python, memory, repeat_and_time
   
   fields = [f"field{i}" for i in range(30)]
   
   
   class CustomOp(DummyOperator):
       template_fields = fields
   
       @apply_defaults
       def __init__(self, *args, **kwargs):
           super().__init__(*args, task_id=kwargs["task_id"])
           for key in kwargs:
               if key.startswith("field"):
                   setattr(self, key, kwargs[key])
   
   
   if __name__ == '__main__':
       N = 10
       DAG_N = 100
   
       @repeat_and_time.timing(N)
       @repeat_and_time.repeat(N)
       def case():
           with DAG("xcomargs_test", default_args={"start_date": 
datetime.today()}):
               op1 = DummyOperator(task_id="op1")
               for i in range(DAG_N):
                   kwargs = {k: op1.output for k in fields}
                   CustomOp(task_id=f"task_{i}", **kwargs)
   
       print("DAGs: ", DAG_N)
       case()
   ```
   Results for 100 DAGs:
   - metaclass: 492.990 ms
   - setattr + if: 7072.531 ms
   - setattr: 7208.424 ms
   
   So using setattr is **14** slower than metaclass... 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to