Conversation
|
I really like the idea of using an I'm always hesitant to add new types to our API since every additional type clutters up our docs page regardless of how niche its use-case is (making it harder for new users to find what they need). But here I think it is possible to actually make the API simpler instead... How would you feel about replacing |
|
I do like the struct on which we can add utility methods, yet agreed we should encourage copying that That would allow falling back to |
|
One annoyance is that any utility methods we add won't be available to the decoder backends (since the How much of a concern is spinning within |
|
It's probably not super realistic issue, but if one thread repeatedly tries to allocate, realizes it won't be enough or some other hazard, thus returns it to try again, then said constant atomic accesses might starve other threads from ever succeeding in their compxchg. I could see someone writing code like that.. This would be okay if the consumption was monotonic but
Maybe we provide strict guidance to implement any So: let me adjust it for more simplicity and documentation. |
|
Also: we should drop |
Could you give an example of a program that would use the new API? In general I expect memory limits to be useful for programs that could operate on adversarial or very unusual images, like image viewers or servers for image processing tasks. (Batch processing and one-shot conversions might use process-level memory limits; video games loading known images wouldn't need limits.) Both image viewers and servers may try to load many images using multiple threads, for which a shared AtomicU64 memory usage estimate could indeed be convenient; but they are also long running, so that after displaying or processing an image the memory used for it would need to be reused. With the current way this PR privatizes the shared limit and then never returns memory back to the shared limit, I don't see how a user could use a single global shared memory limit and load many images without the shared limit running out.
The most general allocation accounting API would probably be a pair of callback functions to request and release memory.... |
Pretty much every program mutating images is adversarial unless you suggest they somehow get magically validated beforehand. |
Yes but pragmatically we're dealing with |
With our
Limitsattributes we encountered issues with using them in a more diverse encoder setting. We often want to share the limits between different components, not all of which are immediately under our control. With the current interface that means predicting, in advance, exactly how many bytes will be needed for each split or the allocation limits would be copied. We can avoid this by a shared atomic variable.Obviously
Limitcan then no longer bePartialEq,EqorHashbut it seems this was only motivated through its use in an error. That part of the interface should be fixed regardless of the changes toLimits.