Skip to content
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

Add temporary object pools #2

Open
coffeenotfound opened this issue Jan 22, 2017 · 6 comments
Open

Add temporary object pools #2

coffeenotfound opened this issue Jan 22, 2017 · 6 comments
Labels

Comments

@coffeenotfound
Copy link
Owner

Add functions for retrieving temporary objects from a pool.
Most of the time Vector and Matrix instances are only needed for some calculations.

As weml types are Float32Arrays, creating loads of short-lived vectors and such may seriously impact performance

@coffeenotfound
Copy link
Owner Author

After doing some minor research I think the GC is good enough and creating temp weml types is fine.

This topic is still open to debate though

@coffeenotfound
Copy link
Owner Author

One point to consider is that the creation of a weml type really isn't that fast, mainly because of the manual Object.assign()

@coffeenotfound
Copy link
Owner Author

I found that it's quite easy to create mulitple temporary vectors, even for seemingly simple calculations. Most of the vectors aren't even needed for long at all.

At that rate, it may actually be benefitial to have object pools. They probably won't even need to hold many elements. As temporary vectors are only needed for one calculation most of the time the pool would just be passing one or two vectors from calculation to calculation.

@coffeenotfound
Copy link
Owner Author

When implemented, the function to retrieve a type should have an optional bool (true by default) that signifies wether to reset the returned type to identity as many operations override the old values anyway.

@coffeenotfound
Copy link
Owner Author

coffeenotfound commented Jan 27, 2017

I'm not too sure whether it's possible have WeakRefs in javascript and even if it were, local vars would keep the references till the end of the function.

So, we need some sort of release function to return them to the pool.

Maybe temporary types should be created with a special release function that has to be called.
It would maybe also be useful to have some pushTemporaryScope and popTemporaryScope functions that make sure all temporary types retrieved in the pushed scope will be returned to the pool.

@coffeenotfound
Copy link
Owner Author

coffeenotfound commented Jan 27, 2017

At the moment the proposed functions are the following:

  • weml.tempVec3(reset) to borrow a temporary Vec3 from the pool (creating a new one if none is unused). reset is a bool and temporary with a default value of true that signifies whether the vector should be reset to identity
  • weml.returnTempVec3(vec) or Vec3.return() to return a temporary Vec3 to the pool. (temporary types should have a _temptype property to speed up the validation of whether the given type actually is a temporary type)

I'm not a big fan of the term "return". Borrow/return is correct in the context of pools but especially the Vec3.return() may be kind of ambiguous, meaning-wise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant