Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Reuse image buffer in HeadlessView - #5476

Closed
mikemorris wants to merge 5 commits into
masterfrom
read-still-image
Closed

mikemorris wants to merge 5 commits into
masterfrom
read-still-image

Conversation

@mikemorris

@mikemorris mikemorris commented Jun 24, 2016 •

Copy link
Copy Markdown
Contributor

Took a shot at wiring @tmpsantos' work on reusing the image buffer in mbgl::HeadlessView into the Node.js bindings, and something is definitely not right, causing segfaults during a benchmark - I'm not entirely sure how to properly handle memory management here, as I can't call image->data.release() with std::shared_ptr<const mbgl::PremultipliedImage> due to const, and some other stuff changed around to use std::unique_ptr::swap instead of std::move.

Can you take a closer look at this @jfirebaugh @tmpsantos, particularly the interaction between Nan::NewBuffer and mbgl::PremultipliedImage::data in NodeMap::renderFinished?

tmpsantos and others added 5 commits June 24, 2016 15:01
So the view can reuse the buffer for the next image. The assumption
is that when the callback gets called it will get the data encoded
to another buffer on PNG or JPEG format.
Avoid big memory allocations, also set a limit to 4096x4096@2 for now.
Now that we have implications on sharing the image buffer, we need
to make sure that we don't have thread concurrency.
@mikemorris mikemorris added the Node.js node-mapbox-gl-native label Jun 24, 2016
@jfirebaugh

Copy link
Copy Markdown
Contributor

I don't think we want to bring std::shared_ptr into this. If you want the view to reuse the PremultipliedImage buffer, then make the callback type void (std::exception_ptr, const PremultipliedImage&).

assert(dimensions[0] <= dimensionsLimits[0]);
assert(dimensions[1] <= dimensionsLimits[1]);

static auto image = std::make_shared<PremultipliedImage>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static means that there is one buffer for the entire process.

@mikemorris mikemorris Jun 24, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, didn't catch that - this doesn't seem workable given how we can have multiple NodeMap objects per node process, each with their own HeadlessView?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static means that there is one buffer for the entire process.

This is exactly the idea. I added an assert to make sure this is always called from the same thread.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to limit HeadlessView to single-threaded programs. We could easily have each HeadlessView own a distinct buffer and still reuse that buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will close this before we spend more bandwidth on it. This branch was never intended to upstream and was initially pushed to my own fork (https://github.com/tmpsantos/mapbox-gl-native/tree/tmpsantos-read_still_image). I suggest we keep experimental branchs on private forks.

@tmpsantos

Copy link
Copy Markdown
Contributor

I don't think we want to bring std::shared_ptr

No, we don't. I replaced with std::shared_ptr because I wanted to prototype if these allocations were causing fragmentation. On my tests on "core only" it didn't make much difference.

@tmpsantos

Copy link
Copy Markdown
Contributor

@mikemorris for testing this branch you have to synchronously encode the buffer into a PNG/JPEG on the renderStill callback which is probably not practical because you want to do that asynchronous on a node worker thread, right?

@tmpsantos tmpsantos closed this Jun 27, 2016
@tmpsantos

Copy link
Copy Markdown
Contributor

@mikemorris I will leave the Delete branchfor you in case you don't have a copy of this branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Node.js node-mapbox-gl-native

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants