Skip to content

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented May 16, 2025

Description of Changes

Annotate rows with their hashes. This is halfway to the old solution of annotating code with their serialized forms; it speeds up insertion into BTreeIndexes while saving a byte array allocation per-row.
(Wait, why do we hash when inserting into BTreeIndexes, you ask? It's because we use a HashSet to store the multiple rows corresponding to a non-unique key.)

This saves work on the main thread repeatedly hashing values. Once we parallelize message processing, this work will be spread out over multiple threads too.

Also adds a data type SmallHashSet<T> for use in BTreeIndexes. This is a struct that can store at most one element without allocating. This gives dramatic allocation reduction on initial connection -- it seems that most rows in BTreeIndexes don't have any other rows with the same key.
Then I manually specialized this, since it's only used on one type -- PreHashedRow. using SmallHashSetOfPreHashedRow instead of SmallHashSet<PreHashedRow> allows us to inline some methods and pass around fewer pointers while hashing things, which is probably good.

API

  • This is an API breaking change to the SDK

Requires SpacetimeDB PRs

Testsuite

SpacetimeDB branch name: master

Testing

I will test:

  • blackholio
  • bitcraft

jdetter and others added 30 commits November 2, 2022 12:01
Add sslEnabled option to Connect function
* Fix compilation issue with master

* Initial push for SATS (still WIP)

* Small build fix

* Small update

* Updates from meeting with Tyler

* Fixed issues with LayoutExplicit and added some missing functions

* AlgebraicValue cleanup

* Copied changes from BitCraftMini

* Removed TypeDef

---------

Co-authored-by: Clockwork Labs <[email protected]>
Co-authored-by: Tyler Cloutier <[email protected]>
Co-authored-by: John Detter <[email protected]>
* Upload script to help deploying to our partners

* You have to specify hosts individually

* Small fix

* Another small fix - tested + working

---------

Co-authored-by: John Detter <[email protected]>
* Serialize byte arrays as hex

* Fix namespace

* Small fix

---------

Co-authored-by: John Detter <[email protected]>
* First pass

* Committing meta file

* Removed option type - unneeded

* Implementing new some converter

* Some converter updates

* Tons of fixes here

* Cleaned up the some/enum serialization implementation

---------

Co-authored-by: John Detter <[email protected]>
* Several updates to the way ClientCache + processing updates works

* Client cache changes working

* Removed log statements

---------

Co-authored-by: John Detter <[email protected]>
* Copied changes from BitCraft

* Applied state diff changes

* State diffs complete

* Compilation fix

* Fix build issues

---------

Co-authored-by: John Detter <[email protected]>
* Pulled SpacetimeUnitySDK from the BitCraft project

* Removed unused logs

* Removed primary key functionality

* Fix compilation issues with older version of C#

* Primary key client implementation

* Another row update fix

---------

Co-authored-by: John <[email protected]>
* Pulled SpacetimeUnitySDK from the BitCraft project

* Removed unused logs

* Removed primary key functionality

* Fix compilation issues with older version of C#

---------

Co-authored-by: John <[email protected]>
* Adding event parameter to table callbacks

* Reverted a namespace change

---------

Co-authored-by: Steve <[email protected]>
Co-authored-by: John Detter <[email protected]>
Co-authored-by: Derek Brinkmann <[email protected]>
* Add onSubscriptionUpdate callback

* Remove unnecesary onTransactionComplete

---------

Co-authored-by: Derek Brinkmann <[email protected]>
* Deserializing reducer args before table updates so they can be accessed from callbacks

* Reducer arguments in table events

* Removed redundant onSubscriptionUpdate

---------

Co-authored-by: Steve <[email protected]>
Co-authored-by: John Detter <[email protected]>
Co-authored-by: John Detter <[email protected]>
Co-authored-by: Steve <[email protected]>
Co-authored-by: John Detter <[email protected]>
* Deserializing reducer args before table updates so they can be accessed from callbacks

* Reducer arguments in table events

* Adding OnBeforeDelete event to tables

* Renaming ReducerCallInfo to ReducerEvent

* Removed extra onSubscriptionUpdate

---------

Co-authored-by: Steve <[email protected]>
Co-authored-by: John Detter <[email protected]>
* Deserializing reducer args before table updates so they can be accessed from callbacks

* Reducer arguments in table events

* Adding OnBeforeDelete event to tables

---------

Co-authored-by: Steve <[email protected]>
Co-authored-by: John Detter <[email protected]>
@kazimuth kazimuth changed the title Pre-hash rows on the message pre-processing thread Pre-hash rows and add SmallHashSets May 16, 2025
@kazimuth
Copy link
Contributor Author

This does mildly pessimize calls to Filter -- it adds a second allocation to them.
SmallHashSet is so good I'm tempted to just use it and get rid of PreHashedRow, not sure.

kazimuth and others added 9 commits May 16, 2025 15:28
## Description of Changes
Just bumping version numbers in preparation for a release.

The Unity SDK and C# SDK had different version numbers. That seems
confusing, so I bumped them both to 1.1.5.

## API

No breaking changes

## Requires SpacetimeDB PRs
None, afaik

## Testsuite
SpacetimeDB branch name: master

## Testing
None

Co-authored-by: Zeke Foppa <[email protected]>
## Description of Changes
Update DLLs to the 1.1.2 versions that have been pushed to NuGet.

The SpacetimeDB tag that they were built from is
`v1.1.2-csharp-release`.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
None, because we're updating the DLLs to essentially include SpacetimeDB
PRs.

## Testsuite
SpacetimeDB branch name: master

## Testing
CI I guess?

Co-authored-by: Zeke Foppa <[email protected]>
## Description of Changes
Bump versions to 1.2.0, as well as update the DLLs from SpacetimeDB
(commit `fc8f7dcc8`). They don't have any changes, but the versions
needed bumping.

## API

This itself is not a breaking changes.

## Requires SpacetimeDB PRs
clockworklabs/SpacetimeDB#2837

## Testsuite
SpacetimeDB branch name: release/v1.2.0

## Testing
CI only

---------

Co-authored-by: Zeke Foppa <[email protected]>
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed

---------

Co-authored-by: Alessandro Asoni <[email protected]>
Co-authored-by: James Gilles <[email protected]>
## Description of Changes
`NetworkRequestTracker` previously was keeping all historical reducer
request data, and searching through this every frame to get statistics.
I've modified it to throw out much more data -- it's much faster now,
but only updates every few seconds.

## API

Not an API break, but deprecates an argument of one of
NetworkRequestTracker's methods to no longer do anything.

Adds new APIs.

## Requires SpacetimeDB PRs
N/A

## Testsuite

SpacetimeDB branch name: master

## Testing

- [x] Tested Bitcraft. **Their F9 debug menu will require an update,
since we now only keep one time window of request data, rather than
being able to give information about multiple windows.** But it works.
- [x] Blackholio CI
@kazimuth
Copy link
Contributor Author

I've added pooling of HashSets within the SmallHashSet class.

kazimuth added 4 commits June 13, 2025 12:33
## Description of Changes
Addresses
clockworklabs/SpacetimeDBPrivate#1786 and
#329.
Marks messages as parsed from the background parsing thread, and then
marks them as applied using a separate tracker once they are applied.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs

## Testsuite

SpacetimeDB branch name: master

## Testing

- [x] Testing against Bitcraft
Copy link
Contributor

@rekhoff rekhoff left a comment

Choose a reason for hiding this comment

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

Assuming all testing goes well, and there are not any significant performance impact, the changes look good and are in-line with the stated goal of the pull request. I've added some minor notes to some comment lines, but that is all. I'm marking this approved.

@@ -226,7 +226,7 @@ internal struct ParsedDatabaseUpdate
// Map: table handles -> (primary key -> IStructuralReadWrite).
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment could use an update, as it still references IStructuralReadWrite.

}

/// <summary>
/// This is a silly object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Though the struct is indeed silly, we may want to provide more context or remove this summary.

}

/// <summary>
/// This is a very silly object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Removal of summary or adding additional context is also needed for this very silly struct.

@kazimuth
Copy link
Contributor Author

I'm not happy with this yet. I'm not entirely convinced it improves performance; in my testing, allocating HashSets from the pool is taking 5% of time to apply an update. But that's under deep profiling, so I have no idea if it's true or not. We could really use better benchmarks.

bfops and others added 4 commits June 23, 2025 18:39
## Description of Changes
Updates the DLLs for
clockworklabs/SpacetimeDB#2762, and bumps our
version numbers as well.

## API

 - [ ] This is an API breaking change to the SDK

Not a breaking change

## Requires SpacetimeDB PRs
None afaik

## Testsuite
SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Ran through Bitcraft tutorial
- [x] Blackholio on CI

---------

Co-authored-by: James Gilles <[email protected]>
Co-authored-by: Zeke Foppa <[email protected]>
## Description of Changes
These version bumps were supposed to happen in
#332,
but apparently I messed something up while I was switching branches.

## API

 - [ ] This is an API breaking change to the SDK

No breaking changes

## Requires SpacetimeDB PRs
None.

## Testsuite
SpacetimeDB branch name: master

## Testing
CI only

Co-authored-by: Zeke Foppa <[email protected]>
## Description of Changes
Missed in
#333.

We should update the 1.2.1 tag and the `release/latest` branch after
this.

## API

 - [ ] This is an API breaking change to the SDK

Nope

## Requires SpacetimeDB PRs
None

## Testsuite
SpacetimeDB branch name: master

## Testing
CI only

Co-authored-by: Zeke Foppa <[email protected]>
@bfops
Copy link
Collaborator

bfops commented Jun 25, 2025

@kazimuth is doing some more testing on this and then we may merge + release it

@bfops
Copy link
Collaborator

bfops commented Aug 8, 2025

Migrated to clockworklabs/SpacetimeDB#3146, as we are merging this repo into that one.

@bfops bfops closed this Aug 8, 2025
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.