james.mcdonell
2018-10-16 14:34:24

@james.mcdonell has joined the channel


bkovitz
2018-10-16 17:31:14

s-exp->fasl tells me that it can’t write a set. Does anyone know why? Or how to work around it to make it save a set?


pnwamk
2018-10-16 17:56:56

@bkovitz it’s because a set is not “a value that could be quoted as a literal—that is, a value without syntax objects for which (compile `’,v) would work and be readable after write. ”



bkovitz
2018-10-16 17:58:32

So, is there a way to make a set into a value that could be quoted as a literal? IOW, how can you fast-save/load a set?


pnwamk
2018-10-16 18:00:57

Turn it into a list would be my first go-to


pnwamk
2018-10-16 18:01:19

(see set->list)


bkovitz
2018-10-16 18:01:31

Hmm. OK. I’ve got some big struct that contains hashes, sets, etc. There’s no way to say “just fasl this thing”?


pnwamk
2018-10-16 18:01:31

(and also list->set)


pnwamk
2018-10-16 18:03:53

off the top of my head I would say if you want to rely on something like fasl, you’ll need a pass that serializes complicated data structures into simpler data that is uniquely identifiable and can be directly tossed to fasl


pnwamk
2018-10-16 18:04:23

and then of course you would need a pass that does the conversion in the other way, after calling fasl->s-exp


bkovitz
2018-10-16 18:04:46

OK, thanks. I’m in the middle of something else right now, but I’ll dig further into how that could work later.


pnwamk
2018-10-16 18:04:50

(prefab structs might be a nice way to tag certain lists as having been sets or other unique data structures)


pnwamk
2018-10-16 18:05:09

someone else might have a better/simpler way


bkovitz
2018-10-16 18:05:21

Ah, that could be a clue. So far, I marked the struct as prefab, but that’s all.


philip.mcgrath
2018-10-16 21:17:26

@bkovitz The output of serialize from racket/serialize can be used as input to s-exp->fasl: http://docs.racket-lang.org/reference/serialization.html?q=serialize#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._serialize%29%29


bkovitz
2018-10-16 23:54:09

@philip.mcgrath Thanks! That worked—for writing. I can write the data to file by calling write, but I can’t read it back by calling read. Do you know which reading function reads data back in from a file so it can be passed to fasl->s-exp?


zenspider
2018-10-16 23:58:16

@bkovitz Is your write output valid? write should: “Writes datum to out, normally in such a way that instances of core datatypes can be read back in.“


bkovitz
2018-10-16 23:59:03

Here’s what I did:


zenspider
2018-10-16 23:59:14

sounds like you would probably benefit from just using read/write for now


bkovitz
2018-10-16 23:59:32

Oops, not quite that. Waiting on DrRacket…


bkovitz
2018-10-17 00:00:52

Here’s the write statement:


zenspider
2018-10-17 00:01:20

I’m also not sure about serialize and fasl and write all in one. That seems prone to problems, no?


bkovitz
2018-10-17 00:01:51

I have no idea. I figure there’s some easy way to save data to a file and re-load it.


zenspider
2018-10-17 00:02:07

what’s wrong with (write medium-slipnet (open-output-file ...)) ?


bkovitz
2018-10-17 00:02:36

I’ll try that right now…


zenspider
2018-10-17 00:02:52

and a plain read to deserialize


zenspider
2018-10-17 00:03:48

the doco has sections for Reader Extension and Writer Extension if you have custom types that choke


bkovitz
2018-10-17 00:04:20

Here’s what I got:


bkovitz
2018-10-17 00:05:08

It’s complaining about #<set: (slipnet archetypes)>).


zenspider
2018-10-17 00:06:19

yeah. you might need a writer/reader extension that know to set->list and list->set for your slipnet


zenspider
2018-10-17 00:06:52

assuming that’s fairly top-level… it’s pretty easy.


bkovitz
2018-10-17 00:07:17

Do serialize and fasl do this already?


bkovitz
2018-10-17 00:08:23

Yeah, I can deserialize and de-fasl with no problem (so far). The only hitch is reading the data from a file.


bkovitz
2018-10-17 00:08:41

How can you just say “slurp in this entire file”?


bkovitz
2018-10-17 00:13:16

I think I just found it…


bkovitz
2018-10-17 00:15:23

s-exp->fasl and fasl->s-exp already save and restore to a file! You can just pass the file as an argument.


philip.mcgrath
2018-10-17 00:26:26

@bkovitz Right now you are creating a byte string (as in bytes?) and then writing that to a file. You can do this, but it is probably not what you want: you probably want to write the fasl binary format directly to the file.


bkovitz
2018-10-17 00:27:20

Hmm, reading it back in is faster than regenerating the data structure from scratch, but still pretty slow.


philip.mcgrath
2018-10-17 00:27:23

Yes—I was making an example, but you figured it out! The fasl functions (now) support reading to and writing from either ports or byte strings.


bkovitz
2018-10-17 00:28:24

Yep, got it! The fasl functions’ args definitely provide a convenient set-up.


philip.mcgrath
2018-10-17 00:29:07

How large is the fasl representation? Hard to say if the time is in disk IO or in deserialize etc.


bkovitz
2018-10-17 00:29:22

The big-slipnet file is 50 megabytes. Probably the next thing I need to look at is how to make this data structure smaller.


philip.mcgrath
2018-10-17 00:29:57

That would be the best thing.


philip.mcgrath
2018-10-17 00:30:33

If you think it’s IO-bound, you could also see if compression would help.


bkovitz
2018-10-17 00:31:05

bkovitz
2018-10-17 00:33:01

The only reason I’m saving the data to disk is to avoid regenerating it every time I run the program. It’s a graph with 123,000 nodes and 300,000 edges. That’s fairly large, but I’ll bet there’s a way to make it in much less than 30 seconds.


bkovitz
2018-10-17 00:35:03

I’ve been profiling the code that makes the graph, and so far nothing stands out as the leading CPU-hog.


bkovitz
2018-10-17 00:38:20

Here are a couple of the leaders. Nearly everything else only takes up small percentages of the total CPU time. This makes me think that if I want it to go fast, I’ll need to convert it to Typed Racket.


bkovitz
2018-10-17 00:40:34

Is there any easy way to find out what parts of the data structure are taking up the most memory? Maybe just using memory more efficiently would also make it faster to create.


samth
2018-10-17 02:21:26

Typed Racket is unlikely to be a major performance win unless you’re doing lots of floating point arithmetic