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
Consider introducing special cases for TypeRefs of small arity #7186
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7186?orig=1 |
@retronym said: {noformat}TypeRef args distribution0 1895430 47.26% I've prototyped a solution that avoids the :: for one-arg type refs. The tradeoff is slower pattern matching on TypeRefs, which now must go through an unapply method. I couldn't measure any different in compiler speed. I also noticed that some TypeRef subclasses had a needless outer pointer, and have eliminated that by unnesting them out of object TypeRef. For fun, I added infrastructure to the Instrumented tests to show the JVM object size. https://github.com/retronym/scala/compare/ticket/7186 I'll extract the changes to slim down TypeRef to another branch and submit a PR, as they are a clear micro-improvement. But I'll leave the first change on the branch; @grzegorz, perhaps you can suggest a scientific way to benchmark the memory impact? I was using YourKit manually, but I didn't have good control over when I took the memory snapshot. |
@magarciaEPFL said: At least for "late closure classes", the new optimizer does a thorough job of squashing unneeded outer pointers, I thought that Constructors would detect (most) cases of redundant outer pointers, isn't that enough? |
@retronym said: e.g. what is different about Types/TypeRef to this example? scala> trait T { val t = "t"; class C { def tt = t }; object O { def foo = new C {} } }
defined trait T
scala> new T{}.O.foo.getClass.getDeclaredFields
res2: Array[java.lang.reflect.Field] = Array() Needs some investigation. |
@magarciaEPFL said: |
@retronym said: That takes TypeRefs from 54 bytes to 40 bytes, by moving usually-null fields to global maps. Back-of-the-envelope-wise, it should save about 2-3% of our retained memory. |
@retronym said: But it would still be great to pin down the real raison d'être for that extra outer field. |
@adriaanm said: |
@adriaanm said: |
@gkossakowski said: |
@retronym said: |
@SethTisue said: |
Jason proposed we would look into special casing TypeRefs that have small arity (probably 0, 1 and 2) in order to reduce memory consumption coming from references to
::
objects.The text was updated successfully, but these errors were encountered: