torsten.grust
2020-11-6 09:44:44

@mflatt Good morning, Matt. Your fix has resolved the student’s problem! Loading/saving .rkt files now works as expected on her machine. I’ve reached out to her to learn if she sees other diagnostic messages now (in her excitement she forgot to report that :wink:), but the fix definitely is a significant step forward.


torsten.grust
2020-11-6 09:45:07

Many thanks again, I highly appreciate the instant attention to the matter. Remarkable.


torsten.grust
2020-11-6 09:45:36

(She used the BC variant, by the way.)


dianatrai7
2020-11-6 10:44:17

@dianatrai7 has joined the channel


mflatt
2020-11-6 11:38:01

Great!

I am surprised, but being surprised helps me look at the problem a different way. I’m finally able to replicate the original error by mangling my Racket preferences file, changing one of the paths in the recorded “recently opened files” list to have a bad byte.

If the student is willing to help test this theory: Under the “File” menu’s “Open Recent” submenu, are there weird entries, probably with with question marks? A copy of the student’s racket-prefs.rktd would also be helpful. Unfortunately, that file is not so easy to locate, but it might be something like Application Data/Roaming/Racket/racket-prefs.rktd in the student’s home directory.

If this theory about a mangled preferences file is right, then I guess the bug really is fixed. It leave the question of how the preferences file was corrupted, but DrRacket shouldn’t fail due to a broken preferences file.


torsten.grust
2020-11-6 12:42:22

The student has supplied the requested pieces:


torsten.grust
2020-11-6 12:42:47

torsten.grust
2020-11-6 12:43:10

There are indeed the weird Unicode symbols you were expecting, Matt.


torsten.grust
2020-11-6 12:44:05

The student also explicitly said that she wants to sincerely thank the Racket devs. Hereby communicated, I hope. ;-)


torsten.grust
2020-11-6 12:45:38

If you need anything else, she’ll be happy to provide it.


mflatt
2020-11-6 13:01:14

Thanks, this is very helpful! It’s concerning that several people have apparently experienced similar corruption of the preferences file, but now we at least know that much.


dmitryhertz
2020-11-6 14:11:37

> What is going on with https://download.racket-lang.org/releases/7.9/catalog/ ? > I cannot install packages via raco. Fixed. Package manager > Settings > add > https://pkgs.racket-lang.org/ The catalog: https://download.racket-lang.org/releases/7.9/catalog/ > remove Now I can migrate packages from 7.8 to 7.9 :slightly_smiling_face:


dmitryhertz
2020-11-6 14:18:31

Hm, interesting. Why CS is so heavy? 199mb (when the regular is 80mb).


samth
2020-11-6 14:28:04

Mostly because it has compiled machine code, whereas BC has bytecode, which is more compact


popa.bogdanp
2020-11-6 19:06:12

In the following code

(struct v (x y)) (match (v 1 2) [(v _ 2) 1]) the _ ends up expanding into an application of unsafe-struct-ref. Would it be possible to optimize racket/match to not do that when fields are being matched after the last _? Or is there some reason it has to do that that I’m missing? I’m working on an interpreter of sorts and adding a location field as the first field of every instruction struct in my interpreter then updating the match clauses to ignore that field increased the execution time of some programs by 40%.



popa.bogdanp
2020-11-6 19:19:47

I see now that there’s a compile-time error when the wrong number of fields is provided in a clause so it seems like all refs due to _ could be eliminated.


samdphillips
2020-11-6 19:35:47

It looks like it may be worse if you have a contracted struct.

https://gist.github.com/samdphillips/7e9e285349ef6427f25b7fc9374ba269


popa.bogdanp
2020-11-6 20:16:14

That makes sense when a struct is contracted, though the fact that it’s that much slower is surprising.


popa.bogdanp
2020-11-6 20:16:38

This change to racket/match seems to resolve the original issue, though I’m still not sure if it’s a good idea or if my approach makes sense:

https://github.com/racket/racket/compare/master...Bogdanp:optimize-struct-match


popa.bogdanp
2020-11-6 20:17:01

Also I’m wondering if I should extend it so that it eliminates unused variable bindings as well.


samth
2020-11-6 20:23:26

I still don’t totally understand the problem


samth
2020-11-6 20:23:58

is the problem that there’s a useless let binding?


popa.bogdanp
2020-11-6 20:24:27

Yep and that binding does an unsafe-struct-ref, which ends up being costly over many iterations.


samth
2020-11-6 20:25:13

I think the optimizer ought to just drop those bindings


popa.bogdanp
2020-11-6 20:25:41

It doesn’t seem to on Racket CS HEAD


popa.bogdanp
2020-11-6 20:30:41

Also, the overhead is even worse for things like:

(time (for ([x 10000000]) (match b [(st a) 'ok]))) The above takes 700ms on my machine, vs 70 for the wildcard version.


samth
2020-11-6 20:35:59

weird, that should behave the same as the wild-card version but with one extra binding


popa.bogdanp
2020-11-6 20:37:02

Yeah, that’s what it expands to:

(let ((b8 b)) (let ((fail9 (λ () (match:error b8 (syntax-srclocs (quote-syntax srcloc)) 'match)))) (cond ((st? b8) (let ((temp11 ((λ (x) (unsafe-struct-ref x 0)) b8))) (syntax-parameterize ((fail (make-rename-transformer (quote-syntax fail9)))) (let ((a temp11)) (let () 'ok))))) (else (fail9)))))


samth
2020-11-6 20:38:04

Racket BC seems to optimize away the binding and the unsafe-struct-ref


popa.bogdanp
2020-11-6 20:38:32

Shall I open a bug report for CS?


samth
2020-11-6 20:38:54

yeah although doing better in match is reasonable too


samdphillips
2020-11-6 20:40:01

maybe chez doesn’t know if unsafe-struct-ref has a side effect?


samth
2020-11-6 20:41:41

certainly CP0 doesn’t know that, especially since it’s a regular Scheme function


samth
2020-11-6 20:41:59

maybe needs to be fixed at the schemify layer


popa.bogdanp
2020-11-6 20:42:14

In (time (for ([x 10000000]) (let ([b1 (st-x b)]) (let ([b2 b1]) 'ok)))) b2 gets optimized away, but not b1


popa.bogdanp
2020-11-6 20:52:32

Er, wait, b is the contracted instance of the struct. The bindings do get optimized away in

(time (for ([x 100000000]) (let ([b1 (st-x a)]) (let ([b2 b1]) (let () 'ok))))) and even in

(time (for ([x 100000000]) (let ([b1 (unsafe-struct-ref a 0)]) (let ([b2 b1]) (let () 'ok)))))


samdphillips
2020-11-6 21:06:18

Does the binding get optimized out in (match v [(vector a _ b) 'ok]) ?


popa.bogdanp
2020-11-6 21:08:01

Doesn’t look like it