Skip to content

perf: improve TFORM CopySpectator performance - #905

Merged
jodavies merged 1 commit into
form-dev:masterfrom
jodavies:tform-copyspectator
Sep 15, 2026
Merged

jodavies merged 1 commit into
form-dev:masterfrom
jodavies:tform-copyspectator

Conversation

@jodavies

Copy link
Copy Markdown
Collaborator

This is a small change to how spectator terms are distributed to TFORM workers. Previously, we ended up creating a huge number of single-term buckets, spoiling efficiency. This now fills the buckets properly.

For a simple benchmark:

#-

#: ScratchSize 500M

Off ThreadStats;
On HumanStats;
On SortVerbose;

Symbol x,n;
CFunction sum;

#ifndef `NTERMS'
	#define NTERMS "{2^25}"
#endif
#define PARTS "{2^6}"
#define TERMSPERPART "{`NTERMS'/`PARTS'}"

Local test = - `NTERMS'*(`NTERMS'+1)/2
	#do p = 0,{`PARTS'-2}
		+ sum(n,{`p'*`TERMSPERPART'+1},{(`p'+1)*`TERMSPERPART'},x^n)
	#enddo
	+ sum(n,{(`PARTS'-1)*`TERMSPERPART'+1},`NTERMS',x^n);
.sort:input-1;
Identify sum(?a) = sum_(?a);
.sort:input-2;

CreateSpectator spec "tmp.`PID_'.spec";

Identify x^n?pos_ = n;
ToSpectator spec;
.sort:to-spec;

CopySpectator zero = spec;
.sort:copy-spec;

Print;
.end

on my usual benchmark machine, with tform -w12, the runtime drops from 32.676 s ± 1.053 s to 13.639 s ± 0.423 s.

The form-bench tests which use spectators don't see any significant improvement.

Benchmark tform-master -w12 runtime (s) tform-copyspec -w12 speedup
forcer 39.24 ± 0.18 s 1.01 ± 0.01
forcer-exp 65.29 ± 0.33 s 1.01 ± 0.01
hyperform 32.84 ± 0.21 s 0.99 ± 0.03

The (non-public) forcer-based benchmark from Andreas also sees essentially no change (tentative 1%?)

Benchmark tform-master -w12 runtime (s) tform-copyspec -w12 speedup
forcer-av POW=6 61.88 ± 0.35 s 1.01 ± 0.01
forcer-av POW=8 177.11 ± 0.08 s 1.00 ± 0.00
forcer-av POW=10 483.52 ± 1.40 s 1.01 ± 0.00

CopySpectator creates a one-term prototype expression in the scratch file. We
must not use this to determine TFORM bucket size, or the master will create an
enormous number of single-term buckets for the workers. Additionally, now that
we properly enter the bucket-filling loop, we need to call GetFromSpectator
instead of GetTermP.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 65.735%. remained the same — jodavies:tform-copyspectator into form-dev:master

@jodavies
jodavies merged commit 39306dd into form-dev:master Sep 15, 2026
106 checks passed
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.

2 participants