-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Reporting] Optimize images buffers handling on PDF generation #136537
Conversation
Pinging @elastic/kibana-app-services (Team:AppServicesUx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dokmic these changes look great, good job digging into the pdfkit library - hopefully a new release will come out soon!
Just curious, what magnitude of memory reduction where you seeing?
Otherwise happy for this to be merged.
x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/worker.ts
Outdated
Show resolved
Hide resolved
content, | ||
content: _.cloneDeepWith(content, (value) => | ||
// The `pdfkit` library used underneath is using `Buffer.from(new Uint8Array(src))` construction to cast the image source. | ||
// According to the Node.js docs, it will create a copy of the source `ArrayBuffer` which should be avoided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
@jloleysens It's hard to get a relative value out of the measurements I took because all the values vary. But I saw a decrease in numbers for the |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
Summary
Resolves #129719.
The original idea was to reuse the virtual file system to pass forward the image buffers to the
pdfmake
library. But it's only supported in version 0.3, which is still in the beta.After inspecting the version 0.2 source code and the underlying
pdfkit
library, there was discovered a more elegant way to achieve the same result. The thing is that thepdfmake
doesn't perform any transformations of the image source and just forwards that down to thepdfkit
. The trick was to convert the transferredArrayBuffer
to aBuffer
instance to avoid inefficient instantiation on thepdfkit
side.After running some local tests against sample data and measuring memory consumption using
process.memoryUsage
, there was some decrease in memory usage.For maintainers