Skip to content

datalog: load takes a run of facts of one relation with one lookup and one insert - #71

Merged
vic merged 1 commit into
mainfrom
datalog-load-runs
Nov 12, 2026
Merged

vic merged 1 commit into
mainfrom
datalog-load-runs

Conversation

@vic

@vic vic commented Nov 12, 2026

Copy link
Copy Markdown
Owner

D.load took each input fact with its own relation id lookup (D.internId, a scan of the relation table), its own D.relOf, and its own insert of the relation back into the rels IMap. A callgrind run of a normal s2c compile put D.load at 14% of all instructions.

Now D.load takes a run of consecutive facts of one relation with one id lookup, one relOf and one insert. The loop is one self tail call over a D.Loading state (a mutual tail call is no C loop), and the rows go into each relation in the same order as before, so every relation and the relation ids are the same.

Measured on s2c compiling itself, both compilers on the same input (perf stat -e instructions:u, twice each):

run before after
normal compile 536,053,661 523,835,200 (-2.28%)
--mem 1,428,089,868 1,399,521,714 (-2.0%)

Checks:

  • The C, stderr and exit code of 830 outputs (prog, cok, cneg, neg, self) are identical, and --mem on s2c is byte-identical.
  • s2c reaches its fixpoint and the seed is updated.

Mutants (one sed line in a copy of s2/datalog.srs; the component tests built from the mutant sources):

mutant killed by
the last run is not inserted into rels datalog (tuples lost), flow, dprov
a run before another relation is not inserted datalog (unreach(e) lost), flow, dprov
a fact inside a run is not added datalog, flow, dprov

@vic
vic merged commit ccf8bc2 into main Nov 12, 2026
3 checks passed
@vic
vic deleted the datalog-load-runs branch November 17, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant