Repository navigation
perf(cache): share a cached definition's attribute and index documents across its reads #1098
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
Closed
+331
−8
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Database; | ||
|
|
||
| /** | ||
| * A clone of a cached collection definition. It shares its attribute and index documents with the definition's | ||
| * kept model, and gets its own copies of a list the first time something reads that list raw, so writes to one | ||
| * clone's nested documents never reach another. Writing through a reference to an element is not supported, as | ||
| * reads go through offsetGet(). | ||
| * | ||
| * @internal | ||
| */ | ||
| final class SharedCollection extends Collection | ||
| { | ||
| #[\Override] | ||
| public function offsetGet(mixed $key): mixed | ||
| { | ||
| $this->unshare($key); | ||
|
appwrite[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| return parent::offsetGet($key); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getIterator(): \Iterator | ||
| { | ||
| $this->unshareAll(); | ||
|
|
||
| return parent::getIterator(); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve clone isolation for array casts.
An array cast bypasses both read overrides. PHP 8.5 copies the
ArrayObjectstorage array without cloning its object elements. (raw.githubusercontent.com)For example:
The write changes the retained definition's
Document. A later$reader->getDocuments('attributes')copies that changed document and returns size999. Previously, eager cloning isolated this write. This is not the excluded reference-write case.Keep eager document cloning unless the shared representation also preserves isolation for array casts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed:
(array) $writerexposes the shared documents, and a write through it reached another reader (size999). PHP userland cannot intercept an array cast on anArrayObject, and the library casts documents in several places, so sharing cannot be made safe here. Closing this PR and keeping the eager clone.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChiragAgg5k Thanks for confirming. I won’t mark the finding as addressed.
Learnings added
You are interacting with an AI system.