Hello everyone,

A while ago I had written a MessagePack library Racket:

Yesterday I made a change to narrow down some of the types from `Any` 
(which is
wrong) to `Packable`. This has tanked my performance to the point where the
tests for non-scalar types (vectors and hashes) time out on the package 
and thus fail.

Please let me provide some context first: MessagePack is a serialisation 
similar to JSON, except binary, so it should be smaller and faster. Only
certain types can be packed (serialised) and unpacked (deserialised). Here 
the specification:

TL;DR: numbers, strings, byte string, booleans, some null element (I use 
and arrays and dictionaries of any of these. I grouped the union of these 
into the compound type `Packable`:

I have also defined a predicate for this new type:

As you can see the `Packable` type is recursive; if an object is a vector 
or a
hash table then all its elements have to be packable as well. Could this be 
reason for the performance loss? Another thing I noticed is that the 
does not provide any proposition, if it succeeds the type checker is not
informed that the object is of type `Packable`. Another is that Typed Racket
seems unable to narrow down the type of the result. Take a look at this

    > (require msgpack)
    > (define bs (call-with-output-bytes (λ (out) (pack 3 out))))
    > bs
    - : Bytes
    > (define v (call-with-input-bytes bs (λ (in) (unpack in))))
    > v
    - : Packable
    > (+ v 3)
    ; readline-input:8:3: Type Checker: type mismatch
    ;   expected: Number
    ;   given: Packable
    ;   in: v
    ; [,bt for context]
    > (exact-integer? v)
    - : Boolean

So the type checker can figure out that v is an integer, but it cannot 
treat it
as one for addition.

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