Giter Club home page Giter Club logo

Comments (16)

stchang avatar stchang commented on July 21, 2024

Thanks, I'll fix it but I'd say this is a bug with Racket. Using in-set with sets seems like a natural thing for programmers to do.

from graph.

stchang avatar stchang commented on July 21, 2024

@samth Actually, I'm not seeing any slowdown (with my existing tests). Are you using with Typed Racket? Do you have an example?

from graph.

samth avatar samth commented on July 21, 2024

This did come from typed racket, where the sequence/c contract is slower than set/c. But you should be able to put in-set in a for loop over the neighbors and get a performance win compared to the sequence version.

from graph.

stchang avatar stchang commented on July 21, 2024

Strangely, I get slower times (by ~15%) without in-set (racket 6.3.0.7).

Without in-set:

$ racket timing-test-in-neighbors.rkt
cpu time: 10221 real time: 10247 gc time: 4
cpu time: 10089 real time: 10113 gc time: 4
cpu time: 10088 real time: 10116 gc time: 0
cpu time: 10177 real time: 10203 gc time: 0
cpu time: 10093 real time: 10122 gc time: 4
cpu time: 10028 real time: 10054 gc time: 4
cpu time: 10005 real time: 10029 gc time: 4
cpu time: 10616 real time: 10643 gc time: 584
cpu time: 10037 real time: 10066 gc time: 0
cpu time: 10045 real time: 10067 gc time: 4

With in-set:

$ racket timing-test-in-neighbors.rkt
cpu time: 8797 real time: 8819 gc time: 8
cpu time: 8724 real time: 8743 gc time: 4
cpu time: 8681 real time: 8705 gc time: 16
cpu time: 8685 real time: 8705 gc time: 0
cpu time: 8680 real time: 8705 gc time: 8
cpu time: 8793 real time: 8814 gc time: 0
cpu time: 8688 real time: 8709 gc time: 0
cpu time: 9369 real time: 9394 gc time: 584
cpu time: 8928 real time: 8953 gc time: 0
cpu time: 8829 real time: 8851 gc time: 8

The test is:

(for ([i 10])
  (time
   (for* ([v (in-vertices g/scc)]
          [u (in-neighbors g/scc v)]
          [w (in-neighbors g/scc u)])
         (void))))

where g/scc has 875714 vertices and 5105043 edges.

from graph.

stchang avatar stchang commented on July 21, 2024

I pushed the test if you want to try it.

from graph.

samth avatar samth commented on July 21, 2024

Somehow I'm unable to run it properly, but what if you take out the in-set in in-weighted-graph-neighbors, and put it in the for loop?

from graph.

stchang avatar stchang commented on July 21, 2024

I changed the test to

(for ([i 10])
  (time
   (for* ([v (in-vertices g/scc)]
          [u (in-set (in-weighted-graph-neighbors g/scc v))]
          [w (in-set (in-weighted-graph-neighbors g/scc u))])
         (void))))

and I get the same (faster) times as above.

from graph.

stchang avatar stchang commented on July 21, 2024

This behavior is consistent with my past experience. Relying on the implicit conversion is generally slower.

from graph.

samth avatar samth commented on July 21, 2024

Right, but the call to in-set ought to be much faster when it can be specialized by the for loop (unless in-set doesn't do that?).

from graph.

stchang avatar stchang commented on July 21, 2024

Right, but the call to in-set ought to be much faster when it can be specialized by the for loop (unless in-set doesn't do that?).

I don't understand this. It is faster with the call to in-set.

from graph.

samth avatar samth commented on July 21, 2024

Right, it is, but not much. Consider these three loops:

(define l (build-list 1000 add1))
(define lseq (in-list l))

(for/sum ([i l]) i)
(for/sum ([i lseq]) i)
(for/sum ([i (in-list l)]) i)

The third one will be much faster (about 5x by my count).

Then do the same for sets. They're all about 10x slower than the slow list ones, and the same speed. So in-set inside a for loop doesn't win, but it should.

from graph.

stchang avatar stchang commented on July 21, 2024

Oh I understand now. You're talking about expand-clause? You're right it looks like it doesn't specialize sets.

from graph.

stchang avatar stchang commented on July 21, 2024

I guess it's because "sets" are generic?

from graph.

samth avatar samth commented on July 21, 2024

Yes, but either that could work better, or we could have in-hash-set.

from graph.

stchang avatar stchang commented on July 21, 2024

Agreed. I'll look into it.

from graph.

stchang avatar stchang commented on July 21, 2024

Started a pull request: racket/racket#1199

from graph.

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.