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
..
functions REQUEST with unknown and undetectable encoding (#600) 2023-08-02 16:49:37 -04:00
imports (core) Improve encoding detection for csv imports, and make encoding an editable option. 2023-08-24 09:50:52 -04:00
acl_formula.py
acl.py
action_obj.py
action_summary.py
actions.py
attribute_recorder.py (core) Allow assistant to evaluate current formula 2023-07-24 21:59:00 +02:00
autocomplete_context.py (core) Make Python tests pass in Python 3.11 2023-07-28 16:37:38 +02:00
codebuilder.py (core) Fix updating attributes inside f-strings when columns are renamed 2023-09-11 14:41:30 +02:00
column.py (core) Fix undo of Ref->Numeric conversion. 2023-09-27 08:53:53 -04:00
csv_patch.py
depend.py
docactions.py
docmodel.py (core) Record Cards 2023-11-19 20:12:37 -05:00
engine.py (core) Avoid quadratic time complexity in fetch_table with query 2023-11-03 13:24:05 +02:00
fake_std_streams.py
formula_prompt.py (core) Use new asttokens.ASTText to support dollar signs inside f-strings 2023-08-23 13:39:28 +02:00
friendly_errors.py
gencode.py
grist.py
identifiers.py
import_actions.py
lookup.py
main.py (core) Allow assistant to evaluate current formula 2023-07-24 21:59:00 +02:00
match_counter.py
migrations.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
moment.py (core) Cache converting timestamp to date 2024-01-08 10:50:50 +02:00
objtypes.py
parse_data.py
records.py
relabeling.py
relation.py
runtests.py
sandbox.py
schema.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
sort_specs.py
summary.py (core) Record Cards 2023-11-19 20:12:37 -05:00
table_data_set.py
table.py
test_acl_formula.py
test_acl_renames.py
test_actions.py
test_codebuilder.py Skip tests involving f-strings for Python 3.9 (#669) 2023-09-11 18:49:30 +02:00
test_column_actions.py (core) Record Cards 2023-11-19 20:12:37 -05:00
test_completion.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
test_default_formulas.py
test_depend.py
test_derived.py
test_display_cols.py (core) Record Cards 2023-11-19 20:12:37 -05:00
test_docmodel.py (core) Record Cards 2023-11-19 20:12:37 -05:00
test_engine.py (core) Avoid quadratic time complexity in fetch_table with query 2023-11-03 13:24:05 +02:00
test_find_col.py
test_formula_error.py
test_formula_prompt.py Skip tests involving f-strings for Python 3.9 (#669) 2023-09-11 18:49:30 +02:00
test_formula_undo.py
test_functions.py
test_gencode.py (core) Make Python tests pass in Python 3.11 2023-07-28 16:37:38 +02:00
test_import_actions.py (core) Record Cards 2023-11-19 20:12:37 -05:00
test_lookups.py
test_match_counter.py
test_migrations.py
test_moment.py
test_record_func.py
test_recordlist.py
test_reflist_rel.py
test_relabeling.py
test_renames2.py
test_renames.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
test_replay.py
test_requests.py REQUEST with unknown and undetectable encoding (#600) 2023-08-02 16:49:37 -04:00
test_rules_grid.py
test_rules.py
test_side_effects.py
test_sort_spec.py
test_summary2.py
test_summary_choicelist.py
test_summary_undo.py
test_summary.py (core) Fix error in sandbox when removing multiple summary source columns 2023-09-27 16:23:49 +02:00
test_table_actions.py (core) Record Cards 2023-11-19 20:12:37 -05:00
test_table_data_set.py
test_temp_rowids.py
test_textbuilder.py
test_treeview.py
test_trigger_formulas.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
test_twowaymap.py
test_types.py
test_undo.py
test_urllib_patch.py
test_user.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
test_useractions.py (core) Record Cards 2023-11-19 20:12:37 -05:00
testsamples.py
testscript.json (core) Sort table._back_references in set to fix nondeterminism in tests 2023-11-20 23:59:46 +02:00
testutil.py
textbuilder.py
treeview.py
twowaymap.py
tzdata.data
urllib_patch.py
user.py (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
useractions.py (core) Allow descriptions for Raw Data tables 2023-12-04 16:52:56 -05:00
usercode.py (core) Make Python tests pass in Python 3.11 2023-07-28 16:37:38 +02:00
usertypes.py
xmlrunner.py