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

Reply via email to