Giter Site home page Giter Site logo

specialization cost about algebra HOT 12 CLOSED

typelevel avatar typelevel commented on September 1, 2024
specialization cost

from algebra.

Comments (12)

non avatar non commented on September 1, 2024

I will run some benchmarks right now to try to quantify what the cost (if any) is, and will report back here with the results.

(Your argument makes sense -- I believe in "trust but verify".)

from algebra.

non avatar non commented on September 1, 2024

So I just modified one of the Spire benchmarks we use to test specialization (spire.benchmark.AddBenchmarks) which is not normally specialized for Byte. I compared the cost of a direct implementation, a non-specialized implementation, and an implementation that was specialized on Byte.

The results were:

[info]             benchmark     us linear runtime
[info]        AddBytesDirect  117.5 =
[info]       AddBytesGeneric  850.7 ====
[info]      AddBytesFullspec  118.2 =

This appears to indicate an 8x slowdown for bytes. This doesn't prove that instances are being allocated: it's possible that this is the cost of using a lookup table. However it does indicate a penalty that we will pay for removing specialization.

I'm still open to discussing whether this is worth it or not.

from algebra.

tixxit avatar tixxit commented on September 1, 2024

So, my personal opinion is that I don't see a ton of value in specializing below Int. Namely, I propose sticking with Int, Long, Float, and Double unless we have a compelling case otherwise. The cost of specialization especially blows up when classes have 2 or more specialized parameters. Scala's Function1 and Function2 don't go beyond these types either.

from algebra.

VladUreche avatar VladUreche commented on September 1, 2024

How about using miniboxing to achieve specialization? I feel it's reasonably stable now, and with the 0.4 release it should address all the quirks of specialization (quirks metabug here), allowing you to simplify the code. And it would certainly reduce the bytecode size, as benchmarks have shown.

Also, if you need any help or bugfixes to make it work, I'd be glad to lend a hand. ;)

from algebra.

non avatar non commented on September 1, 2024

Hi @VladUreche! I have been waiting for you to recommend something like this! That's great news!

I think as a first step I might publish an alternate miniboxed jar in addition to the "standard" one. Do you think that makes sense? That way, users could choose whether they wanted to introduce miniboxing into their build or not.

from algebra.

tixxit avatar tixxit commented on September 1, 2024

Hrmm... @non I think I'll take a stab at that idea... Don't think it'll be too bad.

from algebra.

non avatar non commented on September 1, 2024

@tixxit Awesome, thanks!

from algebra.

VladUreche avatar VladUreche commented on September 1, 2024

I think as a first step I might publish an alternate miniboxed jar in addition to the "standard" one. Do you think that makes sense? That way, users could choose whether they wanted to introduce miniboxing into their build or not.

@non: Yep, that sounds very good! Having released jars built with miniboxing and specialization side by side will not only provide choice to the users, but will also allow us to benchmark them side by side and iron out any performance regressions that may occur. So yes, let's do that!

@tixxit: Awesome! Please let me know if you encounter any issues, I will fix them asap.

from algebra.

johnynek avatar johnynek commented on September 1, 2024

See #30

from algebra.

non avatar non commented on September 1, 2024

After a quick poll of Spire users (at least those who are on the ML and responded) it seems like no one is really relying on Byte or Short.

My concrete proposal to move forward would be to use @sp(Int, Long, Float, Double) in all cases except for Eq, PartialOrder, and Order. I'd like to leave those alone since they are much more general.

What do you think?

from algebra.

tixxit avatar tixxit commented on September 1, 2024

👍

from algebra.

johnynek avatar johnynek commented on September 1, 2024

+1

from algebra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.