perf: replace quadratic List patterns on transact/storage hot paths - #28
Merged
Merged
Conversation
- db.ml diff: (e,a)->values Hashtbl fact tables instead of pairwise List.exists - db.ml refresh_indexes_with_tx_data: batch duplicate-table retract rebuild per tx - db.ml find_active_datom_by_fact: min-fold instead of sort+hd - storage.ml collect_garbage: Hashtbl live set instead of List.mem per node - transact.ml dedupe_facts: (eid,attr)->datoms Hashtbl buckets, order preserved - add .agents/skills/performance (index discipline + banned hot-path patterns)
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the worst quadratic
Listpatterns found by a List-API audit of the engine hot paths (queries returning 30k–70k rows; GC ~26%, List ops ~10% in profiles), and adds aperformanceskill documenting the rules.Db.diff— three whole-dbList.exists (same_fact d)scans per datom made it O(n×m). Now builds(e, a) -> v listHashtbl fact tables for both sides, preservingsame_factsemantics exactly (value_equaltreats NaN=NaN, sovis bucketed per(e,a)rather than hashed directly).Db.refresh_indexes_with_tx_data— duplicate tables were filtered and re-sorted once per retracted datom.remove_facts_from_duplicate_tablesnow buckets all retracted facts by(e,a)and rebuilds each duplicate table once per tx. Per-datomPSet.removecalls are unchanged;Util.compare_datomincludestx, so stale lookups mid-fold only yield no-op removes.Db.find_active_datom_by_fact—List.sort |> List.hd→ single min-fold undercompare_datom Eavt.Storage.collect_garbage—List.mem addressper storage node overlive→Hashtbllive set.Transact.dedupe_facts— assoc-list fold rebuild per datom →(entity_id * attr)Hashtbl buckets; explicitList.revkeeps the old fold's output order.New
.agents/skills/performance/SKILL.mdrecords index-access discipline (bounded seeks vs whole-index walks), the banned hot-path List patterns, and the audited hot-path list.Verified:
dune build impl/clean; all 18 native test exes pass (test_datascript,test_db,test_core,test_issues,test_entity,test_storage,test_upsert,test_tuples,test_serialize,test_listen,test_conn,test_pull_api,test_built_ins,test_lookup_refs,test_query_pull,test_query_engine_fixes,test_util,test_query_namespace).Link to Devin session: https://app.devin.ai/sessions/51aa6b69363a41b9934a684335a2de72
Open in Devin Desktop: https://app.devin.ai/desktop/session/51aa6b69363a41b9934a684335a2de72?variant=devin
Requested by: @tiensonqin