Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(JoinInner): use AVs for keys instead of PVs #1194

Merged
merged 2 commits into from
May 2, 2024

Conversation

Centril
Copy link
Contributor

@Centril Centril commented May 2, 2024

Description of Changes

  1. Reuse join_inner logic from spacetimedb_vm.
  2. Dedup query tests slightly.
  3. Precompute ColIds in join_inner and don't recompute it for every element.
  4. Store AlgebraicValue keys in JoinInner as opposed to ProductValue. This removes an allocation per map entry.
  5. Make JoinInner callbacks infallible.
  6. In JoinInner::next, avoid clones unless necessary.

3-6 collectively, but primarily 4, results in the following perf improvements compared to HEAD~1 on i7-7700K, 64GB RAM:

incr-join               time:   [788.24 ns 790.71 ns 794.34 ns]
                        change: [-15.369% -14.407% -13.168%] (p = 0.00 < 0.05)
                        Performance has improved.

API and ABI breaking changes

None

Expected complexity level and risk

1

@kazimuth kazimuth removed the request for review from joshua-spacetime May 2, 2024 17:58
@Centril Centril enabled auto-merge May 2, 2024 18:28
Copy link
Contributor

@kazimuth kazimuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

crates/vm/src/rel_ops.rs Outdated Show resolved Hide resolved
KeyLhs: FnMut(&RelValue<'a>) -> Result<ProductValue, ErrorVm>,
KeyRhs: FnMut(&RelValue<'a>) -> Result<ProductValue, ErrorVm>,
Pred: FnMut(&RelValue<'a>, &RelValue<'a>) -> Result<bool, ErrorVm>,
KeyLhs: FnMut(&RelValue<'a>) -> AlgebraicValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't return &AlgebraicValue because it might be freshly allocated, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it could at most return Cow<'_, AV> and we might want to attempt that in a follow up and see if it is beneficial.

@Centril Centril added this pull request to the merge queue May 2, 2024
@Centril Centril removed this pull request from the merge queue due to a manual request May 2, 2024
Co-authored-by: james gilles <[email protected]>
Signed-off-by: Mazdak Farrokhzad <[email protected]>
@Centril Centril enabled auto-merge May 2, 2024 20:44
@Centril Centril added this pull request to the merge queue May 2, 2024
Merged via the queue into master with commit e258262 May 2, 2024
6 checks passed
@Centril Centril deleted the centril/faster-join-inner branch May 2, 2024 21:52
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