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

misc: remove scalaxy, use spire.cforRange #866

Merged
merged 11 commits into from
Aug 25, 2020

Conversation

szymonm
Copy link
Contributor

@szymonm szymonm commented Aug 20, 2020

Pull Request checklist

  • The commit(s) message(s) follows the contribution guidelines ?
  • Tests for the changes have been added (for bug fixes / features) ?
  • Docs have been added / updated (for bug fixes / features) ?

Current behavior :

Scalaxy is not released for Scala 2.12, so I'm migrating the codebase to use spire.cforRange (see #457 for more context).

Runs of jmh benchmarks showed that the performance is the same.

If you have any E2E benchmarks, it would be good to run them to verify consistency between synthetic benchmarks and real life...

Szymon Matejczyk added 9 commits August 20, 2020 22:23
Regexes:
s/for \{ (\w) \<\- ([^\W]*) until ([^\W]*) optimized \} \{\{/cforRange { $2 until $3 } { $1 =>

s/for \{ (\w) \<\- ([^\W]*) to ([^\W]*) optimized \} \{\{/cforRange { $2 to $3 } { $1 =>

s/for \{ (\w) \<\- ([^\W]*) until ([^\W]*\.[^\W]*) optimized \} \{/cforRange { $2 until $3 } { $1 =>

s/for \{ (\w) \<\- ([^\W]*) to ([^\W]*\.[^\W]*) optimized \} \{//cforRange { $2 to $3 } { $1 =>

And manual fixes.
@szymonm szymonm changed the title Remove scalaxy, use spire.cfor misc: remove scalaxy, use spire.cforRange Aug 20, 2020
@szymonm szymonm mentioned this pull request Aug 20, 2020
3 tasks
@broneill broneill self-assigned this Aug 24, 2020
Copy link
Contributor

@broneill broneill left a comment

Choose a reason for hiding this comment

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

Nice job! Looks like one case was missed, however.

I also decided to look at the compiled code to see the difference between the old and new code, and it actually looks a bit better with the new cfor macro.

@@ -145,7 +143,7 @@ object UnsafeUtils {
if (wordComp == 0) {
var pointer1 = offset1 + minLenAligned
var pointer2 = offset2 + minLenAligned
for { i <- minLenAligned until minLen optimized } {
for { i <- minLenAligned until minLen } {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed a case here. Should use cforRange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went again through all the changes and didn't spot any more missed cases.

@velvia
Copy link
Member

velvia commented Aug 25, 2020 via email

@broneill
Copy link
Contributor

broneill commented Aug 25, 2020

Here's an example from CompositeOrdering.compare method. Before:

    public int compare(scala.collection.Seq, scala.collection.Seq) {
       <snip>
        iconst_0
        istore_3 // start$macro$2: int
        aload_1 // x: scala.collection.Seq
        invokeinterface int scala.collection.Seq.length()
        istore 4 // end$macro$3: int
        iload_3 // start$macro$2: int
        istore 5 // i$macro$4: int
    L1_46:
        iload 5 // i$macro$4: int
        iload 4 // end$macro$3: int
        if_icmpge L3_119
        iload 5 // i$macro$4: int
        istore 6 // iVal$macro$5: int
        <snip>
    L2_110:
        iload 5 // i$macro$4: int
        iconst_1
        iadd
        istore 5 // i$macro$4: int
        goto L1_46

After:

    public int compare(scala.collection.Seq, scala.collection.Seq) {
        <snip>
        iconst_0
        istore_3 // index$macro$3: int
        aload_1 // x: scala.collection.Seq
        invokeinterface int scala.collection.Seq.length()
        istore 4 // limit$macro$5: int
    L1_43:
        iload_3 // index$macro$3: int
        iload 4 // limit$macro$5: int
        if_icmpge L3_106
        <snip>
    L2_99:
        iload_3 // index$macro$3: int
        iconst_1
        iadd
        istore_3 // index$macro$3: int
        goto L1_43

I omitted the code that stayed the same. The important parts are the "*$macro" local variables, which control the loop in the usual way -- initialize to zero, compare each time, increment each time. The new version uses less local variables, and so it's a bit better. In practice, the HotSpot compiler reduces the use of extra local variables and so the performance of both versions should be the same.

@broneill broneill merged commit 85c3fea into filodb:develop Aug 25, 2020
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.

None yet

3 participants