feat: Add object pooling support with Poolable mixin and ComponentPool#3816
Open
ufrshubham wants to merge 9 commits intomainfrom
Open
feat: Add object pooling support with Poolable mixin and ComponentPool#3816ufrshubham wants to merge 9 commits intomainfrom
Poolable mixin and ComponentPool#3816ufrshubham wants to merge 9 commits intomainfrom
Conversation
Make the pool's maximum size a public final field (maxSize) instead of a private _maxSize, and initialize it via the constructor. Add availableCount getter to report how many components are available. Simplify factory usage by removing the _create helper and calling the factory directly when populating or acquiring.
spydon
reviewed
Feb 22, 2026
Member
spydon
left a comment
There was a problem hiding this comment.
Nice! A few comments on the implementation.
As a follow-up it would be nice to be able to take a pool as an argument in the SpawnComponent.
| double damage = 10.0; | ||
| @override | ||
| void reset() { |
Member
There was a problem hiding this comment.
Couldn't we just tell the users to do this in onMount, then we don't need a new method?
| /// | ||
| /// Note: The pool does not automatically manage the lifecycle of components, so | ||
| /// it is the responsibility of the developer to ensure that components are | ||
| /// properly released back to the pool when they are no longer needed. |
Member
There was a problem hiding this comment.
Couldn't we just listen to removed and add them back to the pool when that happens?
| /// ``` | ||
| /// This mixin is intended to be used with a [ComponentPool] to manage the | ||
| /// lifecycle of poolable components efficiently. | ||
| mixin Poolable on Component { |
Member
There was a problem hiding this comment.
If we tell the users to use onMount, this mixin shouldn't be needed and all components would be able to be poolable
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.
Description
This PR introduces object pooling functionality to Flame through the new
Poolablemixin andComponentPoolclass. Object pooling is a performance optimization technique that reduces garbage collection pressure by reusing component instances instead of creating and destroying them repeatedly.Adds a
Poolablemixin that provides areset()method for components to return to their initial state, and aComponentPool<T>class that manages pooled components with configurable sizing, automatic lifecycle handling, and LIFO behavior.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
NA