Re: [racket-users] Typed Racket has lowered my performance

2017-12-02 Thread HiPhish
> The performance is probably because HashTable and Vector values can be
> mutable, so Typed Racket needs to do extra work to protect them.
> 
> To test this, I cloned msgpack, removed `Vector` from the `Packable`
> type, and changed `HashTable` to `Immutable-Hashtable`. Change here:
> 
https://gitlab.com/bennn1/MsgPack.rkt/commit/2a711200ad0efa1b974a3e5454f69d7004a74996
Thanks, I will change the hash tables to immutable, but I am going to keep 
the
vector as it is until immutable vectors land in Typed Racket. A slow
implementation is better than an incomplete implementation.

> When I run the tests in test/pack/map.rkt, I see:
> - 40 seconds with the types on master
> - 13 seconds with immutable types
> - 9 seconds on commit ac2b005 (before changing the types?)

Why is the version with immutable types still slower? Is it because it has 
to
recursively check the contents of the hash instead of just being satisfied 
with
anything? See, this is the thing that confuses me about Typed Racket, I 
thought
that making types more specific should improve performance or at least 
leave it
as it is because Racket does not have to check types at runtime unless
explicitly requested. Is it because the tests are written in untyped Racket 
and
specifying the Packable type generates a more expensive contract than the 
Any
type would?

> I'm working on a pull request to add Immutable-Vector to Typed Racket.
> That should be ready for the 6.12 release, and then msgpack can make
> the `Packable` type immutable.
> https://github.com/racket/typed-racket/pull/575
> 
> If that PR doesn't solve the performance problem, then I'd be happy to
> keep looking for something that does.
Racket 6.12 should come out around the end of January, right?


> It *should* be possible to make the predicate a proposition by
> changing the type of `packable?` to `(-> Any Boolean : Packable)`. But
> I couldn't get this to type check.
> Here's a simpler case that did work: http://pasterack.org/pastes/92542
>
> But it's probably easier to just use `(define-predicate packable? 
Packable)`
I think the problem is that Packable contains mutable types, which 
according to
the reference manual is not allowed:
https://docs.racket-lang.org/ts-reference/special-forms.html?q=make-predicate#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._make-predicate%29%29


> The type checker doesn't know that `v` is an integer. It just knows
> `v` is Packable. 
Right, that makes sense. Number and Packable intersect, but Packable is not 
a
subtype of Number.

-- 
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] Typed Racket has lowered my performance

2017-12-02 Thread Ben Greenman
> This has tanked my performance to the point where the tests for
> non-scalar types (vectors and hashes) time out on the package
> server, and thus fail.
> https://gitlab.com/HiPhish/MsgPack.rkt/commit/0b6cdc7115389db97a8de2a5175c1feb4c939f8f

The performance is probably because HashTable and Vector values can be
mutable, so Typed Racket needs to do extra work to protect them.

To test this, I cloned msgpack, removed `Vector` from the `Packable`
type, and changed `HashTable` to `Immutable-Hashtable`. Change here:
https://gitlab.com/bennn1/MsgPack.rkt/commit/2a711200ad0efa1b974a3e5454f69d7004a74996

When I run the tests in test/pack/map.rkt, I see:
- 40 seconds with the types on master
- 13 seconds with immutable types
- 9 seconds on commit ac2b005 (before changing the types?)

I'm working on a pull request to add Immutable-Vector to Typed Racket.
That should be ready for the 6.12 release, and then msgpack can make
the `Packable` type immutable.
https://github.com/racket/typed-racket/pull/575

If that PR doesn't solve the performance problem, then I'd be happy to
keep looking for something that does.


> Another thing I noticed is that the predicate
> does not provide any proposition, if it succeeds the type checker is not
> informed that the object is of type `Packable`.

It *should* be possible to make the predicate a proposition by
changing the type of `packable?` to `(-> Any Boolean : Packable)`. But
I couldn't get this to type check.
Here's a simpler case that did work: http://pasterack.org/pastes/92542

But it's probably easier to just use `(define-predicate packable? Packable)`


> Another is that Typed Racket
> seems unable to narrow down the type of the result. Take a look at this
> example:
>
> > (require msgpack)
> > (define bs (call-with-output-bytes (λ (out) (pack 3 out
> > bs
> - : Bytes
> #"\3"
> > (define v (call-with-input-bytes bs (λ (in) (unpack in
> > v
> - : Packable
> 3
> > (+ v 3)
> ; readline-input:8:3: Type Checker: type mismatch
> ;   expected: Number
> ;   given: Packable
> ;   in: v
> ; [,bt for context]
> > (exact-integer? v)
> - : Boolean
> #t
>
> So the type checker can figure out that v is an integer, but it cannot treat
> it as one for addition.

The type checker doesn't know that `v` is an integer. It just knows
`v` is Packable.

-- 
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.