racket / htdp

Other
91 stars 70 forks source link

Problems with very large images #105

Open samth opened 4 years ago

samth commented 4 years ago

With a program with a very large image in it, DrRacket become extremely sluggish, and animate seems to show only a black square some of the time.

To reproduce, in Beginning Student:

(define airplane ...) ;; paste in this image https://image.cnbcfm.com/api/v1/image/106537227-1589463911434gettyimages-890234318.jpeg?v=1589463982
(require 2htdp/image)
(require 2htdp/universe)
(define plane (scale 0.05 airplane))
(image-height plane)
(define (go n) (place-image plane 200 n (empty-scene 400 400)))
(go 0)
(go 50)
(go 150)
(go 250)
(go 350)
(go 450)
(animate go)
mfelleisen commented 4 years ago

Just coping and pasting this image into DrRacket made my instance of drracket go crazy. I started 4 minutes ago and it hasn’t calmed down yet.

— I can’t navigate inside the editor window with key strokes — The wheel keeps spinning. — alt-tab doesn’t bring my drracekt back and forth in a second but in 10 or 15 seconds. — running (define plane …) takes a minute. The wheel keeps spinning. — I haven’t added your program yet .. because I can’t.

Are you sure this is an htdp issue? Tony reported serious graphics issues with CS.

mfelleisen commented 4 years ago

I was able to insert (freeze ..) around the scaled image and things look almost normal now, after drracket loads the program.

samth commented 4 years ago

I eventually let things calm down enough to run my program, and got the behavior I described. I agree that there seem to be DrRacket-related issues as well (cc @rfindler).

This is Racket BC.

mfelleisen commented 4 years ago

This is Racket BC.

What version? I fixed a performnace bug in universe for the spring semester.

samth commented 4 years ago

This was 7.7. I haven't tested 7.8 yet, I'll try tonight.

On Mon, Aug 24, 2020, 6:14 PM Matthias Felleisen notifications@github.com wrote:

This is Racket BC.

What version? I fixed a performnace bug in universe for the spring semester.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/racket/htdp/issues/105#issuecomment-679393455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB3X4433I5Q7ZU7A2EOKXLSCLQ3NANCNFSM4QJZCW4Q .

-- To unsubscribe from this group and stop receiving emails from it, send an email to samth+unsubscribe@plt-scheme.org.

rfindler commented 4 years ago

This looks like one of those situations where it may turn out to be many separate things that need improving. It looks like one of them is saving the file. DrRacket does an autosave pretty quickly after the paste and it takes a long time. Here's some code that just does that part, demonstrating what's slow. I think the autosave timeout is shorter than the time that the saving takes, which compounds things significantly.

#lang racket/gui

(define t (new text%))
(printf "0\n")
(define bmp
  (time (make-object image-snip% "airplane.jpg")))
(printf "1\n")
(time (send t insert bmp))
(printf "2\n")
(time (send t save-file "airplane.rktd"))
(printf "3\n")
rfindler commented 4 years ago

This commit is one piece of the puzzle (meant to note the connection in the commit message but forgot): https://github.com/racket/gui/commit/e947d596bb1eefcc660740a1ba0146188e0e1fc4

rfindler commented 4 years ago

With the latest set of commits, the time it takes to call save-file in the code above goes from 12 seconds to 20ish msec. This matches the time to save in DrRacket when the airplane image is inserted via file|insert image, but when it is pasted in, I see about 5 seconds for the first time the file is saved and then 1ish seconds after that (because there isn't enough information in the paste data (at least that I know how to get) to take the very fastest path).