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

Avoid unnecessary arrayCopy in Kit.readStream #1033

Merged
merged 2 commits into from
Sep 29, 2021

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Sep 20, 2021

This is a small performance optimization, when Kit.readStream is called with the correct stream length. This is always the case, when a file is read. Then fileSize is passed as buffer size.

the old code did the following:

  • declare buffer with file size
  • for loop step # 1
  • perform is.read(...) (reads whole file in the buffer)
  • cursor == buffer.length -> grow buffer array
  • for loop step # 2
  • perform is.read(...) no more to read, break loop
  • shrink buffer array

the new code tries to avoid the two unnecessary arrayCopies by checking if the stream is EOS on first loop.

@rbri
Copy link
Collaborator

rbri commented Sep 23, 2021

Had a second look at this, do you see any notable performance improvement using this - i guess this is a optimization for a really special case?

@rPraml
Copy link
Contributor Author

rPraml commented Sep 24, 2021

@rbri I tried to speed up test execution and discovered this method when building the test cases in Test262SuiteTest.test262SuiteValues()
It calles Test262Case fromSource for all ~20000 test files. In this code path, capacity hint is the file size, so you will save 40000 times arrayCopy,
With this change the Test262SuiteTest.test262SuiteValues() goes down from 13s to 9s.
Unfortunately, the Test262 runs several minutes, so the overall performance gain are only a few percent.

@gbrail
Copy link
Collaborator

gbrail commented Sep 29, 2021

Thanks -- I think it makes sense to do what we can to make the tests run faster!

@gbrail gbrail merged commit 68f6890 into mozilla:master Sep 29, 2021
@p-bakker p-bakker added this to the Release 1.7.14 milestone Oct 13, 2021
@p-bakker p-bakker added the Performance Issues related to the performance of the Rhino engine label Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Issues related to the performance of the Rhino engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants