Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Vlad Ureche
@VladUreche
@DirkToewe: the problem with these small benchmarks is that, assuming the code is fairly simple, the virtual machine JIT inlines everything
and you don't really see the cost of boxing
you only begin to see it when it stops inlining
and then, your performance drops sharply
this is why you're seeing the nice results for the generic for h=1 to 10
otherwise, you'd be seeing a lot uglier results
either way, I'm going to look into the allocation problem
adding a single object allocation breaks optimality
and I want to understand where it comes from
Vlad Ureche
@VladUreche
I just filed the bug for the slowdown: miniboxing/miniboxing-plugin#236
it would be good to also have a look at just the addition part
to see if anything can be improved there
Dirk T.
@DirkToewe
the jvm does not optimize boxing away i believe i checked this before i believe
it's just that the jvm has a "per-thread" heap that is almost as fast as the stack
and once that one is full you get the ramp up in time
Dirk T.
@DirkToewe
i believe they are called TLABs (Thread-local Allocation Buffers) at least on the Hotspot JVM
but i might be wrong on that because it's been like a year since i last experimented with performance on the JVM oder read anything about it
Dirk T.
@DirkToewe
s/oder/or/
Dirk T.
@DirkToewe
The slowdown-graph branch at GitHub is just Your miniboxing example (Test.scala) that i cloned in the first place i believe
Vlad Ureche
@VladUreche
I'll have to think it through
but in general, what happens is that
if you have def foo(o: Object) = o.toString
and def bar = foo(java.lang.Integer(123))
the JVM can inline foo into bar and eliminate the java.lang.Integer allocation
thanks to escape analysis and inlining Integer#toString as well
either way, I have a debug VM where I can print
the entire inlining tree
but I just don't have time right now, I have to focus
on university work until the 26th of June
after that I'll have more time ... I hope
Dirk T.
@DirkToewe
No hurry ... Uni comes first! I wish I could help but I'm afraid I know nothing about compilers. But once you get back to it please let me know.
Vlad Ureche
@VladUreche
Sure, I will ping you once I'm back to this
thanks for the understanding!
Li Yao
@lastland
@VladUreche I've just taken a deeper look at MiniboxedFractional. It seems that the implicit conversion createMiniboxedFractional does not minibox anything, and it just uses the methods from Fractional (not miniboxed, either). Am I missing something?
Vlad Ureche
@VladUreche
@lastland I will check now. The code for type classes is rather new, so there may be a bug.
Vlad Ureche
@VladUreche
@lastland Thanks for bringing this up -- it prompted me to clean up the code in miniboxing/miniboxing-plugin@deef8f6.
to answer your original question, the key to generating MiniboxedFractional classes is the initial pattern match: https://github.com/miniboxing/miniboxing-plugin/blob/wip/components/runtime/src/miniboxing/runtime/math/MiniboxedFractional.scala#L35-L39
you can see that asking for a MiniboxedFractional gives us the object FloatIsMbFractional or DoubleIsMbFractional in the two cases:
1) asking for MiniboxedFractional[T] directly, where T is Float or Double
2) asking for a MiniboxedFractional[T] given a Fractional[T], where createMiniboxedFractional matches the Fractional[Float] and Fractional[Double] instances
Li Yao
@lastland
@VladUreche I see. Thank you for the explanation! :smile:
Vlad Ureche
@VladUreche
@lastland, may I ask what are you working on with miniboxing? Is there anything I can help with?
Li Yao
@lastland
@VladUreche Thanks but right now I’m just checking fun stuff and playing around :wink: Not any practical usage yet.
I have two projects that may benefit from miniboxing a bit, but performance is the not of our concerns right now.
Li Yao
@lastland
I’m also working on a dynamic analysis tool. Boxing and specialization may make a good scenario. We’ll see.
Vlad Ureche
@VladUreche
The dynamic analysis tool sounds interesting. If I can help ping me.
By the way, with scala/scala#4748 and scala/scala#4704 merged into scala/scala the miniboxing plugin should become significantly more stable.
Li Yao
@lastland
Cool! Thanks!