Repository navigation
Conversation
The binding deduplicated number sets with Vec::contains for each element, so set(range(60_000)) took 3 s to convert, with the GIL held on the event loop's thread. The core's duplicate check of sets, set equality and the ADD and DELETE of set elements in the in-memory DynamoDB were quadratic too: a put of that set took 10 s on the memory backend, an ADD 3 s and a DELETE 4.6 s. Number is canonical and hashable, so all of them now use hash sets: 13 ms for the conversion, 40 ms for the put, about 20 ms for ADD and DELETE. Fixes #94 Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
…amoDB Python merged 59_999.0 with 59_999 and Decimal(0) with 0 before the conversion, so the 60,000-element set never reached the deduplication with a duplicate. Floats and Decimals of the same tenths stay apart in Python and are one number in DynamoDB. Co-authored-by: Carl Oscar Aaro <[email protected]>
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.
What and why
Writing a large number set stalled the event loop. The binding deduplicated number sets with a linear search for each element (1 and 1.0 are the same DynamoDB number), so converting
set(range(60_000)), an item of about 210 KB that DynamoDB accepts, took 3.0 s with the GIL held on the event loop's thread, on both backends; a string set of that size took 8 ms. The core was quadratic in the same way: the duplicate check of set values, set equality (conditions and filters with==), and theADDandDELETEof set elements in the in-memory DynamoDB's update evaluation.Numberis canonical and hashable, so all of them now use hash sets. Measured on the in-memory backend with that set: conversion 3.0 s → 13 ms,put9.6 s → 40 ms,ADD3.1 s → 17 ms,DELETE4.6 s → 21 ms, a scan filtering on set equality 2.3 s → 11 ms. Results are unchanged: numbers that are equal in DynamoDB still collapse into one element, and set order still does not matter for equality.Verified with Rust tests of the duplicate check, equality and
ADD/DELETEon sets of 50,000 to 60,000 elements, and a binding test that converts a set of 60,000 Python numbers that are 30,000 DynamoDB numbers (a float and aDecimalof each tenth, which Python keeps apart) into 30,000 elements.make checkpasses.Fixes #94
Checklist
make checkpasses locally (lint, types, clippy, consistency, tests)fctl session
Note
Low risk. It swaps quadratic duplicate checks for hash-set ones in set conversion, set equality and the in-memory
ADD/DELETE, with the same results;Numberis already canonical and hashable, so only performance changes.What it does. Number sets converted from Python, validated, compared and updated (
ADD/DELETE) in the in-memory DynamoDB took time quadratic in their size, so a 60,000-element set stalled the event loop for seconds with the GIL held. The binding's number-set deduplication, the core's duplicate check, set equality and the setADD/DELETEnow use hash sets and run in linear time. It adds Rust tests with large sets, a binding test that converts 60,000 Python numbers that are 30,000 DynamoDB numbers, and a changelog entry.fctl review's first look at
dce049a· 5 files, +84 −29 · Review agent settings