Re: [racket-users] Re: Typed Racket has lowered my performance
Ok, looking more at the commit, I think this is not actually a bug anywhere, but really an unfortunate combination of things that I don't have an idea for improving at the moment. Sorry for not realizing that earlier. First, I think you should just go back to using `Any` in the type for `pack` and for `pack-hash` and `pack-sequence`. I don't think that will cause any problems for you or users of your code, and will make the performance problem go away. For functions where `Packable` appears in the _result_, such as `unpack`, you should keep using `Packable` -- that will be both faster and will avoid contract errors that your users might otherwise encounter. More generally, what happened here was that you made the types you export _more restrictive_ by changing `Any` to `Packable` in the argument types. That is, in the old code, anyone could pass any value to `pack` and either get the result or a dynamic error. That means that Typed Racket could generate a very cheap contract for `pack`. By changing it to a more restrictive type, you get to assume in the body of `pack` that the input is `Packable`, but Typed Racket then generates a very expensive contract to check that. From your code, it doesn't look like you're making use of that additional assumption, so it's just costing you a lot of performance. As to why that contract is so expensive, the short answer is that contracts for mutable data like procedures and hash tables have to construct wrapper objects, which involves a lot of extra allocation and indirection, on top of the usual expense of contract checking. That's why things got faster with Ben's modifications. Finally, why use `Packable` in the result type of `unpack`? Here, the contract for `Any` isn't simple and inexpensive, since you're sharing potentially arbitrary values with untyped code, so Typed Racket constructs a complicated contract (called `any-wrap/c`) in order to protect it. That contract will also error in cases where it doesn't know what to do, which the contract for `Packable` won't. Sam On Sun, Dec 3, 2017 at 6:53 PM, HiPhishwrote: > Anything more I can do? > On Sunday, December 3, 2017 at 6:11:42 PM UTC+1, Sam Tobin-Hochstadt wrote: >> >> Thanks, that's very helpful. It's clear that the contract optimization is >> working in the old code but not the new code, and we need to fix that. > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Typed Racket has lowered my performance
Anything more I can do? On Sunday, December 3, 2017 at 6:11:42 PM UTC+1, Sam Tobin-Hochstadt wrote: > > Thanks, that's very helpful. It's clear that the contract optimization is > working in the old code but not the new code, and we need to fix that. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Typed Racket has lowered my performance
Thanks, that's very helpful. It's clear that the contract optimization is working in the old code but not the new code, and we need to fix that. Sam On Dec 3, 2017 12:07 PM, "HiPhish"wrote: > Here is what happens when I run one of the array tests with the more > restrictive type specifications: > > OK, passed 100 tests. > Running time is 70.75% contracts > 75/106 ms > > (-> (recursive-contract (or/c (and/c hash? (and/c hash-equal ... 75 ms > (lib msgpack/pack.rkt):24:9 > pack 75 ms > > After reverting the commit I get zero overhead: > > OK, passed 100 tests. > Running time is 0% contracts > 0/7 ms > > The contract makes up 70% of the total runtime. I also looks like there is > no > contract generated after reverting. Should I run the profiler on some other > tests as well? > > On Sunday, December 3, 2017 at 3:33:10 PM UTC+1, Sam Tobin-Hochstadt wrote: >> >> Running the contract profiler [1] on your code would be quite helpful. >> >> [1] https://docs.racket-lang.org/contract-profile/index.html >> >> Sam >> > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Typed Racket has lowered my performance
Here is what happens when I run one of the array tests with the more restrictive type specifications: OK, passed 100 tests. Running time is 70.75% contracts 75/106 ms (-> (recursive-contract (or/c (and/c hash? (and/c hash-equal ... 75 ms (lib msgpack/pack.rkt):24:9 pack 75 ms After reverting the commit I get zero overhead: OK, passed 100 tests. Running time is 0% contracts 0/7 ms The contract makes up 70% of the total runtime. I also looks like there is no contract generated after reverting. Should I run the profiler on some other tests as well? On Sunday, December 3, 2017 at 3:33:10 PM UTC+1, Sam Tobin-Hochstadt wrote: > > Running the contract profiler [1] on your code would be quite helpful. > > [1] https://docs.racket-lang.org/contract-profile/index.html > > Sam > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Typed Racket has lowered my performance
Running the contract profiler [1] on your code would be quite helpful. [1] https://docs.racket-lang.org/contract-profile/index.html Sam On Sun, Dec 3, 2017 at 9:29 AM, HiPhishwrote: > Is there anything I can do to help investigate the issue? I have reverted my > commit for the time being, and it's a difference like day and night. > > On Sunday, December 3, 2017 at 12:36:16 AM UTC+1, Sam Tobin-Hochstadt wrote: >> >> I don't think the mutable/immutable issue should be as significant as it >> seems here. Using the Any type shouldn't perform better the way you >> describe, so we need to look more at what the actual contracts are doing. >> >> Sam > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Typed Racket has lowered my performance
Is there anything I can do to help investigate the issue? I have reverted my commit for the time being, and it's a difference like day and night. On Sunday, December 3, 2017 at 12:36:16 AM UTC+1, Sam Tobin-Hochstadt wrote: > > I don't think the mutable/immutable issue should be as significant as it > seems here. Using the Any type shouldn't perform better the way you > describe, so we need to look more at what the actual contracts are doing. > > Sam > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] plot and drracket: beautiful thing
That is Neil Toronto for the plot library. It is a wonder! Robby On Sun, Dec 3, 2017 at 5:36 AM Robert Giraultwrote: > To whomever is responsible for plot and DrRacket working together, this is > just to say that for a moment here I forgot I was using a Lisp. It felt > more like using a software completely devoted to graphing. I can zoom in? > That's wild. Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] plot and drracket: beautiful thing
To whomever is responsible for plot and DrRacket working together, this is just to say that for a moment here I forgot I was using a Lisp. It felt more like using a software completely devoted to graphing. I can zoom in? That's wild. Thanks! -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.