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 bytesRead to FileStream #51

Merged
merged 8 commits into from
Dec 3, 2021

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Dec 1, 2021

Inspired by mscdex/busboy#174 by @ahuigo

FileStream will be similar to FS.ReadStream and provide the attribute bytesRead.

Checklist

lib/types/multipart.js Outdated Show resolved Hide resolved
…eadBytes-to-FileStream

� Conflicts:
�	CHANGELOG.md
@kibertoad
Copy link
Member

kibertoad commented Dec 2, 2021

Before: Mean time for fastify-busboy is 291910.52376131905 nanoseconds
After: Mean time for fastify-busboy is 295153.5812366501 nanoseconds

So approximately 1% loss of performance, which is likely to be within the margin of error.

Of course, it is still faster than the original:
Mean time for busboy is 366253.787385089 nanoseconds

@Uzlopak Thoughts? Personally I think it's acceptable if there is benefit to having this data exposed.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Dec 2, 2021

On second thought I think this is not the best solution. I reread the code and I think we just need to assign nsize in that branch and the branch above when we truncate the file. There is I think no need for the ternary operation. Will check that later.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Dec 2, 2021

Is the mathemal changes made by me correct?

@kibertoad
Copy link
Member

Will be back in few hours and will check!

@kibertoad
Copy link
Member

wonder if we can have interim state unit test for this

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Dec 2, 2021

I actually find it prone to a race condition that I first emit the limit event and later set the bytesRead attribute. That's why I moved the truncated attribute change above the emit.

Should we set the bytesRead above the emit? Additional to the bytesRead below the if block.

In worst case bytesRead is set twice it limit is hit, which is imho acceptable.

Wdyt?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Dec 2, 2021

made it less race condition prone

lib/types/multipart.js Outdated Show resolved Hide resolved
@Uzlopak Uzlopak merged commit b379187 into fastify:master Dec 3, 2021
@Uzlopak Uzlopak deleted the add-readBytes-to-FileStream branch December 3, 2021 07:32
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.

2 participants