Skip to content

Commit

Permalink
even more serializer optimizations. this breaks the serialization for…
Browse files Browse the repository at this point in the history
…mat.

ref #7893

- remove unnecessary extra serialization of length(x.names)
- UTF16String and UTF32String now have compact type tags
- don't serialize () for types with no parameters
  • Loading branch information
JeffBezanson committed Aug 8, 2014
1 parent 32d58f5 commit 31eb8d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 14 additions & 12 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract LongTuple
abstract LongExpr
abstract UndefRefTag

const ser_version = 1 # do not make changes without bumping the version #!
const ser_version = 2 # do not make changes without bumping the version #!
const ser_tag = ObjectIdDict()
const deser_tag = ObjectIdDict()
let i = 2
Expand All @@ -18,7 +18,7 @@ let i = 2
LineNumberNode, SymbolNode, LabelNode, GotoNode,
QuoteNode, TopNode, TypeVar, Box, LambdaStaticData,
Module, UndefRefTag, Task, ASCIIString, UTF8String,
:reserved6, :reserved7, :reserved8,
UTF16String, UTF32String, Float16,
:reserved9, :reserved10, :reserved11, :reserved12,

(), Bool, Any, :Any, None, Top, Undef, Type,
Expand Down Expand Up @@ -270,10 +270,12 @@ function serialize_type_data(s, t)
serialize(s, tname)
mod = t.name.module
serialize(s, mod)
if isdefined(mod,tname) && is(t,eval(mod,tname))
serialize(s, ())
else
serialize(s, t.parameters)
if t.parameters !== ()
if isdefined(mod,tname) && is(t,eval(mod,tname))
serialize(s, ())
else
serialize(s, t.parameters)
end
end
end

Expand Down Expand Up @@ -316,7 +318,6 @@ function serialize(s, x)
if length(t.names)==0 && t.size>0
write(s, x)
else
serialize(s, length(t.names))
for i in 1:length(t.names)
if isdefined(x, i)
serialize(s, getfield(x, i))
Expand Down Expand Up @@ -487,15 +488,13 @@ function deserialize_expr(s, len)
end

function deserialize(s, ::Type{TypeVar})
nf_expected = deserialize(s)
name = deserialize(s)
lb = deserialize(s)
ub = deserialize(s)
TypeVar(name, lb, ub)
end

function deserialize(s, ::Type{UnionType})
nf_expected = deserialize(s)
types = deserialize(s)
Union(types...)
end
Expand All @@ -504,9 +503,13 @@ function deserialize(s, ::Type{DataType})
form = read(s, Uint8)
name = deserialize(s)::Symbol
mod = deserialize(s)::Module
params = deserialize(s)
ty = eval(mod,name)
if is(params,())
if ty.parameters === ()
params = ()
else
params = deserialize(s)
end
if params === ()
t = ty
else
t = apply_type(ty, params...)
Expand Down Expand Up @@ -534,7 +537,6 @@ function deserialize(s, t::DataType)
# bits type
return read(s, t)
end
nf_expected = deserialize(s)
nf = length(t.names)
if nf == 0
return ccall(:jl_new_struct, Any, (Any,Any...), t)
Expand Down
1 change: 0 additions & 1 deletion base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ end
# pidx, which is relevant to the current process only
function serialize(s, S::SharedArray)
serialize_type(s, typeof(S))
serialize(s, length(SharedArray.names))
for n in SharedArray.names
if n in [:s, :pidx, :loc_subarr_1d]
writetag(s, UndefRefTag)
Expand Down

3 comments on commit 31eb8d4

@staticfloat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're breaking compatibility anyway, can we encode the ser_version in the format so we know what version something was serialized with?

@vtjnash
Copy link
Member

@vtjnash vtjnash commented on 31eb8d4 Aug 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean Jeff owes everyone dinner? #7774 (comment)

now I have to go fix Gtk

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API (serialize/deserialize) only supports reading or writing one value at a time. There isn't anything that writes a "file", so there is not yet an obvious place to write a header.

Please sign in to comment.