[racket-users] Canvas animation performance

2021-01-10 Thread making-a-racket
Hello all,

I am embarking upon a project to doing 2D graphics in Racket, so I am 
starting off with various experiments, some of which include testing out 
performance and replicating Processing examples.

I definitely need to do some more reading, but I am wanting to post this to 
get some leads into ensuring I'm utilizing the best performance of the 
racket/draw library and for pointers to portions (or elaborations) of the 
documentation.

In trying to reproducing the LineRendering example that ships with 
Processing, I'm seeing a big performance difference. The Processing sketch 
is:

public void setup() {
  size(800, 600, P2D);  
}
  
public void draw() {
  background(255);
  stroke(0, 10);
  for (int i = 0; i < 5; i++) {
float x0 = random(width);
float y0 = random(height);
float z0 = random(-100, 100);
float x1 = random(width);
float y1 = random(height);
float z1 = random(-100, 100);

// purely 2D lines will trigger the GLU 
// tessellator to add accurate line caps,
// but performance will be substantially
// lower.
line(x0, y0, x1, y1);
  }
}

My Racket code which attempts to reproduce this example is this:

#lang racket/gui

(require racket/draw)

(define WIDTH 800)
(define HEIGHT 600)

(define frame (new frame%
   [label "Lines"]
   [width WIDTH]
   [height HEIGHT]))

(define pen (new pen%
 [color (make-object color% 0 0 0 0.1)]
 [width 1]
 [style 'solid]))

(define (paint canvas dc)
  (send dc set-pen pen)
  (for ([i (in-range 1)])
(send dc draw-line
  (random 0 WIDTH)
  (random 0 HEIGHT)
  (random 0 WIDTH)
  (random 0 HEIGHT

(define canvas (new canvas%
[parent frame]
[paint-callback paint]))

(send frame show #t)

(define (loop)
  (send canvas refresh-now #:flush? #t)
  (sleep/yield 0.033)
  (loop))

(loop)

However, I am not able to obtain anywhere near the performance of the 
Processing sketch, which can draw 50,000 lines at about 12-13fps. It can do 
10,000 at about 40fps. My Racket example can barely do 10,000 lines and is 
definitely below 10fps. I am using Racket CS 7.9 on Windows 10 on an XPS 15 
i7 with dedicated GPU. Even p5.js' performance is well above the Racket 
sample but below the Processing sketch. Another thing that I have noticed 
is that the Processing sketch uses about 90% of the integrated GPU (not the 
dedicated) while Racket only uses about 6% of the integrated GPU. If I try 
to draw 50,000 lines, then Racket (usually) freezes up.

Any thoughts or pointers? If I understood the documentation correctly, 
refresh-now seemed to be the way to get the best frame-by-frame 
performance, but I am certainly still learning. Am I simply hitting the 
performance limit of the racket/draw library or is there something I can do 
to improve things?

I'm still in the programming language/environment selection phase of my 
project, but I would really like to use Racket here.

Thanks for any help!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/535064cd-bc10-42fe-a20a-30623d5b4ca3n%40googlegroups.com.


[racket-users] Re: [ANNOUNCE] New package typed-compose

2021-01-10 Thread unlimitedscolobb
Thank you for the feedback!

I think this macro is a very nice idea and should indeed allow removing 
most compose-i functions, except maybe for compose-3 and compose-4, which 
can be examples of use of make-compose.

I added a Contributing section to the README of the Git repo: 
https://git.marvid.fr/scolobb/typed-compose#contributing . Do you think you 
can make the modifications directly a git clone of my repository and submit 
the changes to me as patches?

-
Sergiu


On Sunday, January 10, 2021 at 6:00:58 AM UTC+1 philngu...@gmail.com wrote:

> Nice package. I don't have an account and don't know how to do pull 
> request on Marvid thing, but I suggest making a macro generating 
> `compose-n` for arbitrary (statically known) n, and export it along side 
> with the predefined compose-n functions, something along these lines:
>
> #lang typed/racket/base
>
> (provide make-compose
>  compose-3 compose-4)
>
> (require (for-syntax racket/base
>  racket/match
>  racket/list
>  racket/syntax
>  syntax/parse))
>
> (define-for-syntax (make-compose-type n)
>   (with-syntax* ([(t ...) (generate-temporaries (make-list n 't))]
>  [a (generate-temporary 'a)]
>  [(_ ... t₀) #'(a t ...)]
>  [(F ...)
>   (let step ([u #'a] [ts (syntax->list #'(t ...))])
> (match ts
>   ['() '()]
>   [(cons t ts*) (cons #`(#,t → #,u) (step t ts*))]))])
> #'(∀ (a t ...) (F ... → t₀ → a
>
> (define-syntax make-compose
>   (syntax-parser
> [(_ n:nat)
>  (with-syntax* ([(f ...) (generate-temporaries (make-list (syntax-e 
> #'n) 'f))]
> [x (generate-temporary 'x)]
> [T (make-compose-type (syntax-e #'n))]
> [body (foldr (λ (fᵢ res) #`(#,fᵢ #,res)) #'x 
> (syntax->list #'(f ...)))])
>#'(ann (λ (f ...) (λ (x) body)) T))]))
>
> (define compose-3 (make-compose 3))
> (define compose-4 (make-compose 4))
> ;; and so on
>
>
>
> On Monday, January 4, 2021 at 12:52:11 PM UTC-8 unlimitedscolobb wrote:
>
>> Hello,
>>
>> I am glad to announce typed-compose, a small package defining some 
>> utilities for composing functions in Typed Racket:
>>
>> https://pkgd.racket-lang.org/pkgn/package/typed-compose
>>
>> Typed Racket's compose only takes two arguments, because in general it 
>> is difficult to specify that the return types and the argument types should 
>> be the same for two successive functions in the argument list. This package 
>> defines some further utilities to allow compose-ing more than two 
>> functions more comfortable in Typed Racket.
>>
>> This is my first ever Racket package, so I'm taking all kinds of feedback.
>>
>> -
>> Sergiu
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/25e19ab5-54ea-40b2-a1c0-621982b520a9n%40googlegroups.com.


Re: [racket-users] History changes

2021-01-10 Thread Ben Greenman
> It would be nice if I don’t have to modify scribble-lib, or, failing that,
> avoid touching documenting forms. Isn’t it possible for history to know
> which defform it’s under?

A history might not appear under a defform (for better or worse).

Maybe it's easier to give a list of links to the new history items. A
patch to @history could make an index tag ... something like
"h:7.4.0.3:hashtables" ... and then the search box might be good
enough to build a list of links.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R4v%3Dr30mikcTuD64UhKhuChD9z_9EZRf-7VweFX0_Be4g%40mail.gmail.com.


[racket-users] History changes

2021-01-10 Thread Sorawee Porncharoenwase
Hi Racketeers,

Laurent Orseau asked if it’s possible for the release announcement to
include @history changes (compared to the previous release), because some
small but useful changes might go unnoticed otherwise. I think this is a
great idea, so I tried to implement the feature. The result for 8.0 release
is included at the end of the email. However, I’m not satisfied with my
current approach, and I would appreciate it if anyone could suggest a way
to improve it.

My current workflow is:

   1. Download two Racket versions that I want to diff @history.
   2. Patch share/pkgs/scribble-lib on both versions
   3. Run raco setup -c scribblings; HISTORY_INFO_PATH=/path/to/info raco
   setup scribblings on both versions
   4. Run the diffing program on the two info files.

Patching scribble-lib is something I want to avoid. Specifically, I need to
modify scribble-lib to

   - modify history to recognize HISTORY_INFO_PATH and emit information.
   This alone is enough to get all information except the “who I am” field
   (see below)
   - modify all documenting forms, like defform, defproc, etc. so that it
   cooperates with history to supply “who I am” field. This is further
   complicated by the fact that deftogether exists, so I need to hack the
   with-togetherable-racket-variables protocol to keep the information
   around.

It would be nice if I don’t have to modify scribble-lib, or, failing that,
avoid touching documenting forms. Isn’t it possible for history to know
which defform it’s under?
Anyhow, here's the output for v8.0

who: #%declare
package: base
source: racket-doc/scribblings/reference/syntax.scrbl:433:19
desc:
  Changed in version 7.9.0.5: Added #:unsafe.


who: system-type
package: base
source: racket-doc/scribblings/reference/runtime.scrbl:132:19
desc:
  Changed in version 7.9.0.6: Added 'os* and 'arch modes.


who: _cprocedure
package: base
source: racket-doc/scribblings/foreign/types.scrbl:780:19
desc:
  Changed in version 7.9.0.16: Added the #:varargs-after argument.


who: _fun
package: base
source: racket-doc/scribblings/foreign/types.scrbl:916:19
desc:
  Changed in version 7.9.0.16: Added the #:varargs-after option.


source: racket-doc/scribblings/raco/setup.scrbl:383:19
desc:
  Changed in version 7.9.0.3: Added PLT_SETUP_NO_FORCE_GC,
PLT_SETUP_SHOW_TIMESTAMPS, and --sync-docs-only.


source: racket-doc/scribblings/raco/decompile.scrbl:37:19
desc:
  Changed in version 1.9: Added --partial-fasl.


package: compiler-lib
source: racket-doc/scribblings/raco/test.scrbl:198:19
desc:
  Changed in version 1.8: Added --output and -o.


package: base
source: racket-doc/scribblings/reference/syntax-model.scrbl:450:19
desc:
  Changed in version 7.9.0.13: Added implicit-made-explicit properties.


who: fx+/wraparound
package: base
source: racket-doc/scribblings/reference/fixnums.scrbl:104:17
desc:
  Added in version 7.9.0.6.


who: bytes-open-converter
package: base
source: racket-doc/scribblings/reference/bytes.scrbl:520:19
desc:
  Changed in version 7.9.0.17: Added built-in converters for "WTF-8",
<"WTF-8-permissive", and "WTF-16".


who: hash-intersect
package: base
source: racket-doc/scribblings/reference/hashes.scrbl:795:17
desc:
  Added in version 7.8.0.11.


package: base
source: racket-doc/scribblings/reference/cont.scrbl:105:19
desc:
  Changed in version 7.9.0.13: The name argument gives the name of the
prompt tag.


who: object-name
package: base
source: racket-doc/scribblings/reference/struct-inspectors.scrbl:191:20
desc:
  Changed in version 7.9.0.13: Recognize the name of continuation prompt
tags.


who: unsafe-fx+/wraparound
package: base
source: racket-doc/scribblings/reference/unsafe.scrbl:91:17
desc:
  Added in version 7.9.0.6.


who: unsafe-set-immutable-car!
package: base
source: racket-doc/scribblings/reference/unsafe.scrbl:306:17
desc:
  Added in version 7.9.0.18.


who: editor:silent-cancel-on-save-file-out-of-date?
package: gui-lib
source: gui-lib/framework/main.rkt:1634:18
desc:
  Added in version 1.53.


who: make
package: gui-lib
source: gui-doc/scribblings/gui/tab-panel-class.scrbl:65:19
desc:
  Changed in version 1.55: Added the 'can-reorder and 'can-close styles.


who: on-reorder
package: gui-lib
source: gui-doc/scribblings/gui/tab-panel-class.scrbl:121:17
desc:
  Added in version 1.55.


who: on-close-request
package: gui-lib
source: gui-doc/scribblings/gui/tab-panel-class.scrbl:132:17
desc:
  Added in version 1.55.


who: on-superwindow-activate
package: gui-lib
source: gui-doc/scribblings/gui/window-intf.scrbl:481:19
desc:
  Added in version 1.54.


who: message-box/custom
package: gui-lib
source: gui-doc/scribblings/gui/dialog-funcs.scrbl:355:19
desc:
  Changed in version 1.53: Added the return-the-dialog? argument and the
ability to change the dialog box's message.


who: message+check-box
package: gui-lib
source: gui-doc/scribblings/gui/dialog-funcs.scrbl:388:19
desc:
  Changed in version 1.53: Added the return-the-dialog? argument and the
ability to change the