xlwings Performance
Felix Zumstein, 25 June 2020
Webinar
Agenda
1. MinimizeCross Border Calls
2. Raw Values
3. UDF Server (Win only)
4. Caching
5. App Properties
2
Code Samples
https://github.com/xlwings/xlwings-demo/tree/master/performance
3
1. Minimize Cross Border Calls
Minimize Cross Border Calls
• Use arrays (both in scriptsand UDFs)
– Nested lists, NumPy arrays, pandas DataFrames
• A goodworkflow is:
– read the data
– do the magic in Python
– write the results back
5
2. Raw Values
Raw Values
• Faster, especiallyfor writingbig DataFrames
• sheet['A1:B1'].raw_value = arr
• @xw.ret('raw') / @xw.arg('x', 'raw')
• Uses the platform-specificlow-level librarieswithoutthe convenience
layer, i.e. datacleaning!(pywin32 andappscript)
• Requires you to calculatethe dimension
7
3. UDF Server (Win only)
Use UDF Server
• Keeps Python sessionalive
• UsingRunPythonwill make it cross-platformcompatible,butyouneed to
”Restart UDF server” after each code change
• Windows-only:Use @xw.subdecorator andImport Subs like you import
UDFs
9
4. Caching
Caching
• Built-in:functools.lru_cache (leastrecently used)
11
@lru_cache()
@xw.func
def slow():
time.sleep(5)
return 'done'
• Third-partypackages, e.g. cachetools
5. App Properties
App Properties
• myapp.screen_updating = False
• myapp.calculation = 'manual'
13
Thank You
Let’s connect: https://www.linkedin.com/in/felix-
zumstein

xlwings performance