Files
gristlabs_grist-core/sandbox/grist
Alex Hall fa6b57855e (core) Cache converting timestamp to date
Summary: Adds `@functools.lru_cache` to `ts_to_dt` and `ts_to_date` which are used in `_make_rich_value` in Date/DateTime columns, i.e. every time such a column is accessed in a formula. I noticed that these operations are surprisingly expensive while working on https://phab.getgrist.com/D4075. This is just an easy way to potentially significantly speed up certain docs and formulas.

Test Plan:
Put this code in an engine test case:

```
def test_(self):
  self.apply_user_action(["AddTable", "Table1", [
    {"id": "A", "type": "DateTime:America/Chicago"},
  ]])
  self.add_records("Table1", ["A"], [
    [i] for i in range(1000)
  ])
  formula = "for _ in range(1000): $A\nreturn 1"
  import time
  start = time.time()
  self.add_column(
    "Table1", formula, type="Any", isFormula=True, formula=formula
  )
  elapsed = time.time() - start
  print(f"Took {elapsed:.2f} for formula {formula}")
```

The time goes from ~10s to ~1s. Similar tests showed no noticeable slowdown when caching had no effect.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D4099
2024-01-08 10:50:50 +02:00
..
2022-06-17 21:53:20 +02:00
2023-11-19 20:12:37 -05:00
2023-11-19 20:12:37 -05:00
2023-11-19 20:12:37 -05:00
2023-11-19 20:12:37 -05:00
2023-11-19 20:12:37 -05:00
2022-02-19 09:46:49 +00:00
2023-11-19 20:12:37 -05:00
2022-05-04 21:41:42 +02:00
2023-11-19 20:12:37 -05:00
2023-11-19 20:12:37 -05:00