You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When reading about consuming a text file, or a stream with scala.io.Source, most literature recommends using Source.fromInputStream(...).mkString.
This, however, incurs a terrible performance penalty, presumably because of how Iterator.mkString is implemented. This performance issue is prevented by calling Source.getLines.mkString.
The issue is reproducible by the attached source file.
The text was updated successfully, but these errors were encountered:
@vigdorchik said (edited on Apr 11, 2013 12:48:26 PM UTC):
scala.io.Source extends Iterator[Char], so mkString is naturally slow, has nothing to do with Iterator performance. Surely this is a bad advise to get the content of the file this way.
Shai Yallin (electricmonk) said:
My point is that the fact that it extends an Iterator[Char] is kind of an implementation detail; ideally it represent an abstraction over some source of input.
Bad advice as it is, community-speaking this seems to be the common knowledge of how to consume a Source, which - as I said - is bad.
@Ichoran said:
Overloading mkString is an easy fix. Retrofitting a Char-customized iterator into Source would improve performance in other cases also. Will do one or the other; being able to conveniently get the entire contents of a file is a fundamental feature of an i/o library.
When reading about consuming a text file, or a stream with scala.io.Source, most literature recommends using Source.fromInputStream(...).mkString.
This, however, incurs a terrible performance penalty, presumably because of how Iterator.mkString is implemented. This performance issue is prevented by calling Source.getLines.mkString.
The issue is reproducible by the attached source file.
The text was updated successfully, but these errors were encountered: