Skip to content

Generate json in the threadpool #103

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

springmeyer
Copy link
Contributor

@springmeyer springmeyer commented Nov 26, 2018

This is an experimental PR that moves the JSON response creation to happen, asynchronously, in the C++ threadpool. The motivation here is:

  • This will result in less main event loop blocking, since the v8 object creation it replaces was happening synchronously
  • This will result in less allocations and therefore less garbage collection churn and pauses, since we're now creating a single JS object to hold the response string rather than many small objects to form up the JSON tree
  • Now that we pass across a single string as a response, in the future if we wanted to compress the response it would be easy to do in the threadpool using gzip-hpp before sending across the threadpool.

Caveats:

  • This works, but likely needs more testing
  • This is probably not as fast as it could be since:
    • std::to_string is used heavily and is know to be not as fast as specialized conversion methods
    • string concatenation is used and requires small C++ allocations. We could likely save on allocations by using a StrCat approach like https://abseil.io/tips/3

/cc @mapbox/maps-api @mapsam

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

Successfully merging this pull request may close these issues.

1 participant