Skip to content

Specialize Functions #3306

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

Closed
wants to merge 32 commits into from
Closed

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Oct 11, 2017

Supersedes #1807 by @felixmulder

What I changed compared to the previous version:

  • The previous version would change the parent of a class extending FunctionN to the specialised version, if it existed. I encountered several issues doing that, and my investigation led me to believe that doing so is not necessary in this particular case. From my reading of @dragos's thesis, §4.4.2 "Specialized inheritance", it appears that changing the parent to the specialised version is important to have the child inherit the specialised functions rather than the generic ones. My understanding is that this is not necessary in this particular case, please let me know if I am misunderstanding the issue.

  • The optimisation wouldn't apply on by-name parameters, because it would run before ElimByName. I didn't manage to shuffle the phases around without adding a new traversal.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@Duhemm Duhemm mentioned this pull request Oct 11, 2017
3 tasks
@Duhemm
Copy link
Contributor Author

Duhemm commented Oct 11, 2017

test performance please

@dottybot
Copy link
Member

performance test scheduled: 2 job(s) in queue, 0 running.

val typeParams = tp.cls.typeRef.baseType(func).argInfos
val interface = specInterface(typeParams)

if (interface.exists && tp.decls.lookup(nme.apply).exists) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating a class symbol with specInterface and checking if it actually exists, you can use isSpecializableFunction like in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala#L39

dt.vparamss.head.map(_.symbol.info)
)

val specializedApply = tree.symbol.enclosingClass.info.decls.lookup(specName)
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here and in transformApply, you should only have to do the lookup if isSpecializableFunction returns true

case _ => tree
}

@inline private def specializedName(name: Name, args: List[Type])(implicit ctx: Context) =
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's any reason for this method and the next one to be marked @inline

r <- List(UnitType, BooleanType, IntType, FloatType, LongType, DoubleType)
t1 <- List(IntType, LongType, DoubleType)
t2 <- List(IntType, LongType, DoubleType)
} yield specApply(func2, List(t1, t2), r)
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates some logic from isSpecializableFunction

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3306/ to see the changes.

Benchmarks is based on merging with master (b8d1e41)

@smarter
Copy link
Member

smarter commented Oct 11, 2017

Most of the performance cost is probably from splitting a phase group to add SpecializeFunctions. Would be great if we could figure out a way to avoid that.

@allanrenucci allanrenucci added this to the 0.5 Tech Preview milestone Oct 17, 2017
@Duhemm Duhemm force-pushed the topic/specialize-func1-rebased branch from cd2766f to e916a67 Compare October 28, 2017 15:14
@Duhemm
Copy link
Contributor Author

Duhemm commented Oct 28, 2017

I think I managed to re-unify the group I split 🎉

@Duhemm
Copy link
Contributor Author

Duhemm commented Oct 28, 2017

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

performance test failed:

Error line number: 145

[check /data/workspace/bench/logs/pull-3306-10-28-17.33.out for more information]

@liufengyun
Copy link
Contributor

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3306/ to see the changes.

Benchmarks is based on merging with master (68cc7ee)

@liufengyun
Copy link
Contributor

test performance please

(meta test for bench infrastructure change)

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@liufengyun
Copy link
Contributor

test performance please

(meta test for bench infrastructure change)

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3306/ to see the changes.

Benchmarks is based on merging with master (68cc7ee)

@Duhemm Duhemm force-pushed the topic/specialize-func1-rebased branch from f5250fe to 5ecc4aa Compare November 6, 2017 08:20
@Duhemm
Copy link
Contributor Author

Duhemm commented Nov 6, 2017

test performance please

@dottybot
Copy link
Member

dottybot commented Nov 6, 2017

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

dottybot commented Nov 6, 2017

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3306/ to see the changes.

Benchmarks is based on merging with master (22ff8a4)

@smarter
Copy link
Member

smarter commented Nov 6, 2017

Looks like this PR still affects performance, even the empty file benchmark seems to get slower. It'd be good to try to figure out where the extra time is being spent and if we can optimize this.

@Duhemm Duhemm force-pushed the topic/specialize-func1-rebased branch from 5ecc4aa to a32b06f Compare November 19, 2017 14:34
@Duhemm
Copy link
Contributor Author

Duhemm commented Nov 19, 2017

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3306/ to see the changes.

Benchmarks is based on merging with master (635d668)

@allanrenucci allanrenucci removed this from the 0.7 Tech Preview milestone Jul 23, 2018
@Duhemm Duhemm closed this Nov 28, 2018
@Duhemm Duhemm deleted the topic/specialize-func1-rebased branch November 30, 2018 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants