Code Monkey home page Code Monkey logo

Comments (3)

hmans avatar hmans commented on July 18, 2024

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.

hmans avatar hmans commented on July 18, 2024

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.

CGamesPlay avatar CGamesPlay commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.