Comments (3)
Hi, and thanks for submitting this!
First of all, which version of Miniplex are you using exactly? Your code looks like you're using one of the 2.0 betas — which one?
To be entirely fair, I'm not sure if there really is a memory leak, or if there is one, that it's because of the archetype creation. A call to world.with("section")
will be idempotent, only creating the actual archetype on its first call; on subsequent calls, the memoized archetype will be returned. archetype.where(predicate)
won't even create any new archetype instances, but just a temporary iterator that allows you to iterate through archetype
, with the predicate
function applied.
If for some reason multiple instances of the same archetype are being created, that would be a bug. May I ask what steps you took to identify this memory leak? Thanks!
from miniplex.
Addendum: I'm honestly surprised that the code example you've posted here works at all, considering you're creating an iterator using where
and passing that to your version of useEntities()
, which will try to call .onEntityAdded
et al on it, which should raise an error because those events don't exist on the iterator object where
returns.
I'm assuming you're using 2.0b3 — please let me know if this is wrong.
The implementation of where
is here, for reference.
Heads-up: because the nature of how where
works has proven a bit iffy to explain to people, it'll be removed in the next beta. If things go as planned, the next beta will also come with a significant reduction in API surface and implementation complexity (but it'll be a breaking change, so be ready.) See #275 for details.
from miniplex.
Sorry, I should have mentioned. I am using ^2.0.0-beta.3
, which is apparently [email protected]
. Also, the code snippet in my original is what I'd like to do, rather than what I am presently doing (which is using a normal archetype and filtering manually). 🫢 Given that you're saying it wouldn't work, well, it wouldn't be a leak either, I guess!
What I really want is to have a component that only rerenders when the entities selected by the predicate change. My actual code presently caches the world.with("section")
globally, which is advised in the current README, and then as I mentioned I filter out other entities in my render method. This causes unnecessarily component renders of the list which I was hoping to avoid.
If you're moving towards the API you describe in #275, it would be awesome to have something like this (again, this is just pseudocode):
function MyList({ section }) {
const entities = useQuery(world, React.useCallback(
q => q.with("location").where(e => e.location.section === section),
[section]
));
return (<div>...</div>);
}
If it's possible to create such a useQuery
hook, it would greatly reduce my number of rerenders.
from miniplex.
Related Issues (20)
- `archetype.first`
- [Idea] Allow `World.add` to take a setup function as an optional second argument
- Offer bound `ECS.useEntities(world => bucket)` API
- `useCurrentEntity` should throw when not run inside an entity context
- <Entity> will destroy and re-create its entity on every rerender
- `Query` (for 2.0)
- Publish `@miniplex/bucket` as `bucketeer`
- Offer a ref-based capture mechanism alongside the `<Component>`-based one
- Remove all mentions of "archetypes" from the documentation, refer to "queries" instead
- Apply new `onEntityAdded` listeners to entities that are already in the query
- Research how well Miniplex works with class instances as entities (!) HOT 1
- Support setting components directly on `<Entity>`
- Miniplex 2.0 Release Checklist HOT 1
- Accessing Entity Defined in Player Function from App.jsx File HOT 1
- Best way to represent multiple entities? HOT 2
- miniplex + rapier = 💔? HOT 2
- Serialization and rehydration HOT 1
- Compared to Bitecs.js's ECS architecture mode, does EC mode perform better?
- Query evaluation against outdated version of entity in nested component removal requests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miniplex.