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

Bring back windows performance improvements #20423

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object BestEffortTastyWriter:
unit.pickled.foreach { (clz, binary) =>
val parts = clz.fullName.mangledString.split('.')
val outPath = outputPath(parts.toList, dir)
val outTastyFile = new PlainFile(new File(outPath))
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)
val outTastyFile = new File(outPath)
val outstream = new DataOutputStream(new PlainFile(outTastyFile).bufferedOutput)
try outstream.write(binary())
catch case ex: ClosedByInterruptException =>
try
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/io/AbstractFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
/** Does this abstract file represent something which can contain classfiles? */
def isClassContainer: Boolean = isDirectory || (jpath != null && ext.isJarOrZip)

/** Create a file on disk, if one does not exist already. */
def create(): Unit

/** Delete the underlying file or directory (recursively). */
def delete(): Unit

/** Is this abstract file a directory? */
def isDirectory: Boolean

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/io/NoAbstractFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import java.io.InputStream
object NoAbstractFile extends AbstractFile {
def absolute: AbstractFile = this
def container: AbstractFile = this
def create(): Unit = ???
def delete(): Unit = ???
def jpath: JPath = null
def input: InputStream = null
def isDirectory: Boolean = false
Expand Down
13 changes: 2 additions & 11 deletions compiler/src/dotty/tools/io/PlainFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import java.nio.file.{InvalidPathException, Paths}

/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
override def isDirectory: Boolean = true
override val isDirectory: Boolean = true
override def iterator(): Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_))
override def delete(): Unit = givenPath.deleteRecursively()
}

/** This class implements an abstract file backed by a File.
Expand Down Expand Up @@ -78,7 +77,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
}

/** Is this abstract file a directory? */
def isDirectory: Boolean = givenPath.isDirectory
val isDirectory: Boolean = givenPath.isDirectory // cached for performance on Windows
Copy link
Member

@bishabosha bishabosha May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I assume is that this was a def because create() and delete() exist - but if they were never used does that mean in all code paths we never create/delete a directory before (but after object construction)/after testing isDirectory? (e.g. with java.nio api) - because then that might change behaviour especially if the object is cached somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in the original PR that was a concern, as this was a def because of the create and delete methods, but needed to be changed in the PR to a val for performance. As you mention this conflicted with the create() and delete() methods, but they turned out to not be used anywhere, so they were removed. From what I see in dotty PlainFiles and PlainDirectories always use java File api for creating and deleting the files and VirtualFiles and VirtualDirectories use internal representation, so they end up not needing the create and delete methods (because for that we call new or just dereference them from other VirtualDirectories). The exception here was the (now removed) call to PlainFile.delete() added after the CI pass of the original PR, which caused the conflicts on main


/** Returns the time that this abstract file was last modified. */
def lastModified: Long = givenPath.lastModified.toMillis
Expand Down Expand Up @@ -113,14 +112,6 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
null
}

/** Does this abstract file denote an existing file? */
def create(): Unit = if (!exists) givenPath.createFile()

/** Delete the underlying file or directory (recursively). */
def delete(): Unit =
if (givenPath.isFile) givenPath.delete()
else if (givenPath.isDirectory) givenPath.toDirectory.deleteRecursively()

/** Returns a plain file with the given name. It does not
* check that it exists.
*/
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/io/VirtualDirectory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ extends AbstractFile {
override def input: InputStream = sys.error("directories cannot be read")
override def output: OutputStream = sys.error("directories cannot be written")

/** Does this abstract file denote an existing file? */
def create(): Unit = { unsupported() }

/** Delete the underlying file or directory (recursively). */
def delete(): Unit = { unsupported() }

/** Returns an abstract file with the given name. It does not
* check that it exists.
*/
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/io/VirtualFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
Iterator.empty
}

/** Does this abstract file denote an existing file? */
def create(): Unit = unsupported()

/** Delete the underlying file or directory (recursively). */
def delete(): Unit = unsupported()

/**
* Returns the abstract file in this abstract directory with the
* specified name. If there is no such file, returns null. The
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/io/ZipArchive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ abstract class ZipArchive(override val jpath: JPath, release: Option[String]) ex
def isDirectory: Boolean = true
def lookupName(name: String, directory: Boolean): AbstractFile = unsupported()
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = unsupported()
def create(): Unit = unsupported()
def delete(): Unit = unsupported()
def output: OutputStream = unsupported()
def container: AbstractFile = unsupported()
def absolute: AbstractFile = unsupported()
Expand Down