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

Use classpath PathRefs hashCode as cache key for Scala.js worker #2183

Merged
merged 3 commits into from
Dec 10, 2022

Conversation

lolgab
Copy link
Member

@lolgab lolgab commented Dec 9, 2022

This makes the bridge method take 15ms instead of 600ms (in my machine) since it is not needed anymore to perform file system operations. But we use the already existing Agg[PathRef] as the key to cache Scala.js workers.

@lolgab lolgab force-pushed the faster-scalajs-worker branch 2 times, most recently from 026e883 to 77ac0f9 Compare December 10, 2022 10:34
@lolgab lolgab marked this pull request as ready for review December 10, 2022 12:16
@lolgab lolgab requested a review from lefou December 10, 2022 12:23
private def bridge(toolsClasspath: Agg[mill.PathRef])(implicit ctx: Ctx.Home) = {
// toolsClasspath is stable and made of external libraries which have the versions
// in the file names. So we use the paths string to hash since it's ~50x faster
val classloaderSig = toolsClasspath.iterator.map(p => p.path.hashCode).sum
Copy link
Member

Choose a reason for hiding this comment

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

I think using the hashCode of the PathRef is a better option. Using only the name is not guaranteed to be stable. E.g. you could dynamically download to a same local path T.dest / "out.jar" and would miss any change when this jar changes later.

This makes the `bridge` method take 15ms instead of 600ms
It is safe since the filenames contain the Scala.js version, so if
you switch version the hashCode will be different as expected
@lolgab lolgab force-pushed the faster-scalajs-worker branch from 77ac0f9 to 8a32ac7 Compare December 10, 2022 16:30
@lolgab
Copy link
Member Author

lolgab commented Dec 10, 2022

I naively thought that calculating the hashcode of PathRefs was more expensive than of Paths but the price of PathRefs is on creation. Once you have it, you don't need to perform any file system operation to calculate the hashCode, which is great. Also the hashCode of a Agg is exactly .map(_.hashCode()).sum so we can use that directly.

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

This looks good to me. After you update the PR title and description, I think we are good to go.

@lolgab lolgab changed the title Use only classpath paths strings to cache Scala.js worker Use classpath PathRefs hashCode as cache key for Scala.js worker Dec 10, 2022
@lolgab lolgab requested a review from lefou December 10, 2022 19:42
@lolgab
Copy link
Member Author

lolgab commented Dec 10, 2022

@lefou Done! Thank you for the review! I'm so happy about these performance improvements. Mill is noticeably faster!

@lefou
Copy link
Member

lefou commented Dec 10, 2022

@lefou Done! Thank you for the review! I'm so happy about these performance improvements. Mill is noticeably faster!

Do you have any numbers?

EDIT: Oh, you already provided them in the description. Yeah, nice speed up!

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

Nice change! Less code, better performance.

@lefou lefou merged commit 5234477 into com-lihaoyi:main Dec 10, 2022
@lefou lefou added this to the 0.11.0-M1 milestone Dec 10, 2022
@lolgab lolgab deleted the faster-scalajs-worker branch December 10, 2022 20:30
lolgab added a commit to lolgab/mill that referenced this pull request Dec 10, 2022
…om-lihaoyi#2183)

This makes the `bridge` method take 15ms instead of 600ms (in my
machine) since it is not needed anymore to perform file system
operations. But we use the already existing `Agg[PathRef]` as the key to
cache Scala.js workers.

Pull request: com-lihaoyi#2183
lefou pushed a commit that referenced this pull request Dec 12, 2022
@lefou lefou mentioned this pull request Feb 18, 2023
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