1
$\begingroup$

I have a problem with the following piece of Mathematica code:

A = Import["fileA.mx"];
B = Import["fileB.mx"];

The following evaluates to True:

A === B

however the size of one file is about 10 times greater then the size of the other one.

Both files were created in Mathematica using the same Export["<some file>.mx" , <some expression>] incantation. What's going on here?

$\endgroup$
  • 1
    $\begingroup$ Are you sure they were both created with Export and not with DumpSave? $\endgroup$ – Carl Woll Jun 7 '17 at 14:33
  • $\begingroup$ Export was used for both A and B. I think I figured out what was going on.It looks like it all boils down to how MX stores files. I'll use a small example (in reality the tables were much larger), exporting: {Table[0 , {64} , {64}] , 1 , 2 , 3 , {Table[0 , {64} , {64}]}} will produce a much larger MX file size then: {zerotable , 1 , 2 , 3 , {zerotable}} with zerotable = Table[0 , {64} , {64}] evaluated beforehand. $\endgroup$ – user34705 Jun 8 '17 at 4:51
1
$\begingroup$

I think I figured out what was going on.It looks like it all boils down to how MX stores files. I'll use a small example (in reality the tables were much larger), exporting:

{Table[0 , {64} , {64}] , 1 , 2 , 3 , {Table[0 , {64} , {64}]}}

will produce a significantly larger MX file size then exporting:

{zerotable , 1 , 2 , 3 , {zerotable}}

with

zerotable = Table[0 , {64} , {64}]

evaluated beforehand.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Interesting find. Particularly as Export doesn't have HoldRest on it... $\endgroup$ – b3m2a1 Jun 8 '17 at 5:05
0
$\begingroup$

Just as an extension on user34705's answer, as that had me very intrigued, the way Export works with the "MX" format is by passing the values to System`Private`ConvertersPrivateDumpSymbol and calling DumpSave on that.

The fascinating thing is that, even for something like:

With[{z = Table[0, {64}, {64}]},
 With[{f = Export[CreateFile[], {z, z, z}, "MX"]},
  (DeleteFile[f]; #) &@FileByteCount[f]
  ]
 ]

we get the smaller byte count.

And this is despite the fact that System`Private`ConvertersPrivateDumpSymbol stores the true expression.

So somehow it knows, internally, that z inside that is shared whereas with the explicit version it does not.

No idea how it knows that, but it probably has to do with Share

A very cool find by user34705.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.