Speed difference between GUI and Terminal

Hello,

i ran an intensive computation that compute a logical expression put in disjonctive minimal form that takes 14' to compute in GUI.

and i experienced problems displaying on macintosh the subscript character k: ₖ

it will display the code in a box in the GUI of Racket:

i known it is only a problem of font under mac os ,installing Deja Vu font or other solve the problem which is quite uneasy under Mac OS, i then ran it in terminal with DrRacket because in Terminal the display of k is ok ,Terminal use the right font. But i'm surprised to get the result in 7' 50" which is even a little better than in Python with Sympy and twice faster than with Racket GUI:

/Applications/Racket\ v8.6/bin/racket -f start-logic-command-line.rkt -i
C₁₃ = ((B₁ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁) ∨ (B₂ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁) ∨ (B₂ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂) ∨ (B₃ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂) ∨ (B₄ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁) ∨ (B₅ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂) ∨ (B₆ ∧ B₇ ∧ B₉ ∧ B₁₁) ∨ (B₇ ∧ B₈ ∧ B₁₀ ∧ B₁₂) ∨ (B₈ ∧ B₉ ∧ B₁₁) ∨ (B₉ ∧ B₁₀ ∧ B₁₂) ∨ (B₁₀ ∧ B₁₁) ∨ (B₁₁ ∧ B₁₂))

in Python:
C₁₃ = (B₁₀ & B₁₁) | (B₁₁ & B₁₂) | (B₁₀ & B₁₂ & B₉) | (B₁₁ & B₈ & B₉) | (B₁₀ & B₁₂ & B₇ & B₈) | (B₁₁ & B₆ & B₇ & B₉) | (B₁₀ & B₁₂ & B₅ & B₆ & B₈) | (B₁₁ & B₄ & B₅ & B₇ & B₉) | (B₁ & B₁₁ & B₃ & B₅ & B₇ & B₉) | (B₁₀ & B₁₂ & B₂ & B₄ & B₆ & B₈) | (B₁₀ & B₁₂ & B₃ & B₄ & B₆ & B₈) | (B₁₁ & B₂ & B₃ & B₅ & B₇ & B₉)

my question is about the speed performance twice slower of Racket in GUI rather than in Terminal ? why? (with a program that do not do any output or graphic, a simple expression output as result)

another thing but it is more Python related, i know my Scheme program in logic manipulate big expression (10Gb for C13) when i measure Python memory it use only some Mb of memory but i'm not sure it is the size used by Python interpreter or my python code in SymPy ? (use more?)

PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS
2758 Python 99.8 04:04.70 5/1 1 49 62M+ 0B 0B 2753 2753 running *0[1] 0.00000 0.00000
2786 DrRacket 90.8 02:21.57 20/1 6 306 2129M+ 736K- 0B 2786 1 running *1[11] 1.28197 0.00000

reached 10Gb with my scheme program:

PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS
2786 DrRacket 91.9 08:22.72 19/1 5 306 10G 0B 3899M- 2786 1 running *1[11] 0.57104 0.00000

Damien

my question is about the speed performance twice slower of Racket in GUI rather than in Terminal ? why

The program run by DrRacket and racket is not the same.
DrRacket augments your program in order to improve the debugging experience.
Look at the settings in the languge menu.

i can not find the same options as in terminal mode , i checked 'no debugging or profiling' and after 'debugging and profiling' but it change nothing in speed.
I'm am in
#lang reader "racket/SRFI-105.rkt"
perheaps it does not apply.

One difference is that printing to the DrRacket is slower than printing in the terminal.

Try timing the calculation without the printing.
Also make sure "Populate "compiled" dictories" is on.
And remove the "preserve stacktrace".

That is, try:

(define result (time <compute>))
(displayln result)

no, i try all it change nothing, i did not use 'time' because it is uneasy and anyway there is only printing in the first minute at beginning and at end (15th minute),at the opposite in terminal it ends at 7th minute.

I am running out of ideas wrt the cause.

Do you by chance have a low memory limit in DrRacket ? - if so disable it.

for sure no, instead the memory limit is pushed to 8192Mb:

Welcome to DrRacket, version 8.6 [cs].
Language: reader "racket/SRFI-105.rkt", with debugging [custom]; memory limit: 8192 MB.

because the minterms list can grow a lot in the computation, and the program halt with a 'out of memory' if not.
What is strange is that in command line there is no need for setting the memory limit and it works.

Running a Racket program at the command time doesn't impose a memory limit. DrRacket by default imposes a memory limit and other sandboxing measures around programs it runs to prevent a bug in your code from interfering with DrRacket's responsiveness. (See custodian-limit-memory and racket/sandbox if you want to do similar things.

This message says with debugging [custom], which means that you still have some debugging instrumentation enabled. That will certainly slow things down.

This could be written as just (time <compute>).

More broadly, DrRacket and the programs it runs share the same Racket process. Despite the isolation mechanisms DrRacket uses, even if you disable all of the debugging instrumentation, there will be overhead in memory use (which will change the garbage collector's behavior) and wall-clock time. It's expected for performance to be better when running a program directly than when running it under DrRacket. (Of course, how significant the difference is varies from program to program.)

with those options i have performance half way from before and Terminal mode (3minutes less over 14minutes):

upgrading from Racket 8.6 to 8.7 yesterday the code is 45" slower in Terminal (not checked in GUI)

Welcome to DrRacket, version 8.7 [cs].
Language: reader "racket/SRFI-105.rkt" [custom]; memory limit: 8192 MB.

I'm confused because with the advice you got in the previous comments, the time in the CLI and DrRacket should be very similar.

How are you storing the expressions internally? Are they syntax objects, or custom structs or a tree of pairs or just a string? If you are using syntaxs, they have a lot of additional properties that are useful for macros anr reporting errors, but perhaps DrRacket is adding an additional property that is dup^n-licated and cause a problem.

I recommend to run the code again using the internal time function, becaue it shows the total time and the gc time, so it may give a hint. Moreover, try to run examples of expressions of different length, so it's possible to guess an "experimental" complexity order that may give another hint.

Can you run it also in DrRacketBC? I don't expect that to be useful but some internal parts are slightly different and there is a tiny chance that the result is different.

so, i perform test with 'time on exactly the same code:

in DrRacket GUI:

Welcome to DrRacket, version 8.7 [cs].
Language: reader "racket/SRFI-105.rkt" [custom]; memory limit: 8192 MB.
'()
> (time (compute-quiet 12 #t))
cpu time: 57516 real time: 60097 gc time: 12995
'((B₁ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₃ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₄ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₅ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₆ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₇ ∧ B₈ ∧ B₁₀)
  ∨
  (B₈ ∧ B₉ ∧ B₁₁)
  ∨
  (B₉ ∧ B₁₀)
  ∨
  (B₁₀ ∧ B₁₁))

in CLI:

/Applications/Racket\ v8.7/bin/racket -f start-logic-command-line.rkt -i
Welcome to Racket v8.7 [cs].
'()
> (time (compute-quiet 12 #t))
cpu time: 40865 real time: 42249 gc time: 8992
'((B₁ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₃ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₄ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₅ ∧ B₆ ∧ B₈ ∧ B₁₀)
  ∨
  (B₆ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₇ ∧ B₈ ∧ B₁₀)
  ∨
  (B₈ ∧ B₉ ∧ B₁₁)
  ∨
  (B₉ ∧ B₁₀)
  ∨
  (B₁₀ ∧ B₁₁))

still different time.

About the code the main procedure is not public for now but it is only 300 lines, it uses my library of minimal logic form:

approx 4000 to 10000 lines with the whole library

i suppose it uses what you call syntax object as i use the quoted scheme syntax to represent logic expressions.

about DrRacket BC , i do not understand what is it ,even if spent a few minutes reading the doc :frowning:

Welcome to DrRacket, version 8.7 [cs].
> (time (compute-quiet 12 #t))
cpu time: 57,516 real time: 60,097 gc time: 12,995

Welcome to Racket v8.7 [cs].
> (time (compute-quiet 12 #t))
cpu time: 40,865 real time: 42,249 gc time: 8,992

I expected a 10% or 20% difference. This is like a 50% increase, that is more than what I expected. Can you post the numbers of (compute-quiet 13 #t)?

@robby: Is DrRacket adding a big property to syntax? Like coloring or a more detailed position. (I'm just guessing that it may cause a problem.) Is it possible to "clean" them?

About RacketBC: It's the old version of Racket, the default up to the version 7.9, like two years ago, that used a compiler written in C. The new Racket is RacketCS, the default from version 8.0, that uses a compiler written in Chez Scheme. Both versions are almost equal, so you are safe to ignore the difference unless you are using extensions in C or something. The default download is RacketCS 8.7, but from the download page you can also download RacketBC 8.7. I guess it's unrelated, so ignore this suggestion.

[Edit: fix RacketBC -> RacketCS in the middle of the last paragraph.]

I don't think so but it is hard to be sure what's going on! It should be the case that DrRacket'll be slower only because there is just more stuff loaded into the heap when the settings are as discussed above.

1 Like

my last computation were on Apple M1

today i use Intel Linux.

I notice the fastest is when disabling ALL options (even the submenu)

in DrRacket GUI:

Welcome to DrRacket, version 8.6 [cs].
Language: reader "racket/SRFI-105.rkt" [custom]; memory limit: 14000 MB.
'()
 (time (compute-quiet 12 #t))
cpu time: 81154 real time: 80916 gc time: 20873

in CLI Racket:

Welcome to Racket v8.6 [cs].
'()
> (time (compute-quiet 12 #t))
cpu time: 70456 real time: 70455 gc time: 17248
 code here

temporary conclusion there is less difference between CLI an GUI under Linux Intel than MacOS M1
i will redo tests on M1 as soon as possible anyway an C13 test on Intel Linux tomorrow i think,apparently i have a few problem (proccess halted) under linux intel, possibly with memory >10 Gb which is not under MacOS (2 systems have 16Gb memory also).

thank you for your info on Racket BC.

I expect the slow down perheaps due to different graphic system between Linux (X-windows?) and Mac OS (Carbon?Cocoa?Xquartz???no this one was Xwindows too?)

Side note:

Shift+cmd+4 allows you to capture a part of the screen.

Take a screenshot on your Mac - Apple Support.

yes :slight_smile: (for the screenshot)

here my result for C13 in DrRacket GUI under Apple M1:

(time (compute 13 #t))
cpu time: 645368 real time: 686639 gc time: 218905
'((B₁ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₃ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₄ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₅ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₆ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₇ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₈ ∧ B₉ ∧ B₁₁)
  ∨
  (B₉ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₁₀ ∧ B₁₁)
  ∨
  (B₁₁ ∧ B₁₂))

and in CLI Racket, i added this for both (even if in GUI the max memory can be fixed differently):

;; Set limit
(custodian-limit-memory
   (current-custodian) (* 14 1024 1024 1024)) ;; 14 Gb

and the result in CLI:

(time (compute 13 #t))
cpu time: 497764 real time: 517229 gc time: 195757
'((B₁ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₃ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₂ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₃ ∧ B₄ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₄ ∧ B₅ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₅ ∧ B₆ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₆ ∧ B₇ ∧ B₉ ∧ B₁₁)
  ∨
  (B₇ ∧ B₈ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₈ ∧ B₉ ∧ B₁₁)
  ∨
  (B₉ ∧ B₁₀ ∧ B₁₂)
  ∨
  (B₁₀ ∧ B₁₁)
  ∨
  (B₁₁ ∧ B₁₂))

approximatively 25% difference between CLI and GUI

even it is just strange for Racket but not a problem for me,
anyway i use emacs, almost never use debugger or macro expander and subscript char display better in CLI than GUI.

1 Like

I understood that C13 was still x2 slower in DrRacket than in the CLI. If the difference is only a 25%, I guess it's not solvable (as someone else explained above).

I mostly run my programs in DrRacket, but I'm not using too Racket for heavy calculations.

yes 2x was with all options, what is strange is that some options are labelled 'faster loading' and 'inlining'
and i was thinking it will speed up the code but instead it is the opposite. I think too that there is nothing to do for the 25% difference.