Revert imperative Utility.escape from 81d7e2a #102
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current version of
scala.xml.Utility.escape
was contributed in 81d7e2a for scala/bug#3014. The method was changed for an issue concerning control characters. Benchmarking at that time happened to show that Scala 2.7 had either a poor performing implementation forIterator
orMap
or both. This produced anescape
function that was "3x-4x" slower than an imperative version using a while-loop and a pattern match.Attached to the Jira issue is an
XmlThing.scala
benchmark program. I've re-run the benchmark program, and there's no evidence that the implementation is any faster than the original code in fc79c58.I modified the
XmlThing.scala
program: I limited the test to 1-million iterations, down from 100-million so that the tests would take a second rather than a minute. I then ran the tests in groups of 384, and ran the implementations in different order.I ran it with JMH, as well:
Here's the trial data (JMH is the second sheet):
https://docs.google.com/spreadsheets/d/1xZakvCKpZjaRO1QRMv3WySz4H6nGsNUgSMDm52pqKpM/edit?usp=sharing
Cheers to @vshalts for writing an SBT task that can run a program X times.
https://gist.github.com/vshalts/ed389bfb69b017f4dac7150cf0875529