ueshin opened a new pull request, #47308:
URL: https://github.com/apache/spark/pull/47308

   ### What changes were proposed in this pull request?
   
   Reduce the overhead of `_capture_call_site` by inline `inspect.stack` with 
using `generator` instead of `list`.
   Also, specify `context=0` for `inspect.getframeinfo` to avoid unnecessary 
field retrievals.
   
   ### Why are the changes needed?
   
   The `_capture_call_site` has inevitable overhead when `Column` operations 
happen a lot, but we can reduce it.
   
   E.g.,
   
   ```py
   from functools import reduce
   
   def alias_schema():
       return df.select(reduce(lambda x, y: x.alias(f"col_a_{y}"), range(20), 
F.col("a"))).schema
   profile(alias_schema)
   ```
   
   <img width="1106" alt="Screenshot 2024-07-11 at 15 24 31" 
src="https://github.com/user-attachments/assets/1c677f56-86be-4e8f-9dd2-45c4c2c167f3";>
   
   The function calls and duration are:
   
   - before
   
   ```
           18013240 function calls (18012760 primitive calls) in 2.327 seconds
   
      ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   ...
         200    0.001    0.000    2.231    0.011 
/.../python/pyspark/errors/utils.py:164(_capture_call_site)
   
   ```
   
   - after
   
   ```
            1421240 function calls (1420760 primitive calls) in 0.265 seconds
   
      ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   ...
         200    0.001    0.000    0.182    0.001 
/.../python/pyspark/errors/utils.py:165(_capture_call_site)
   
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   The existing tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to