Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU usage due to contracts #10

Open
srcreigh opened this issue Jun 6, 2020 · 1 comment
Open

High CPU usage due to contracts #10

srcreigh opened this issue Jun 6, 2020 · 1 comment

Comments

@srcreigh
Copy link

srcreigh commented Jun 6, 2020

Thanks for the easy to use lib @zyrolasting .

I'm a racket noob so go easy on me.

The file-watchers package dominates my CPU (99% CPU for any process that uses it). I tried both intensive-watch and robust-watch. I ran a quick profiling script and seems like 99.9% of the time is spent checking contracts. Using the defaults.

I may look into this further but thought I'd ping you now in case you have some tips.

#lang racket/base

(require file-watchers
         profile)

(profile-thunk (λ ()
                 (define th (watch (list (find-system-path 'orig-dir))
                                   displayln displayln
                                   robust-watch))
                 (sleep 10)
                 (kill-thread th))
               #:threads #t)

outputs:

====================================================================================
                               Caller
 Idx   Total       Self      Name+src                                         Local%
       ms(pct)     ms(pct)     Callee
====================================================================================
 [1] 3454(99.9%)    0(0.0%)  loop ...cket/7.6/pkgs/file-watchers/main.rkt:56:21
                               ??? [3]                                        100.0%
------------------------------------------------------------------------------------
 [2]    1(0.0%)     0(0.0%)  repl-thunk ...-20200403.1450/racket/repl.rkt:267:6
                               call-with-expanded-syntax-caching-evaluator [4]100.0%
------------------------------------------------------------------------------------
                               loop [1]                                       100.0%
 [3] 3454(99.9%) 3454(99.9%) ??? ...contract/private/arrow-val-first.rkt:486:18
------------------------------------------------------------------------------------
                               repl-thunk [2]                                 100.0%
 [4]    1(0.0%)     0(0.0%)  call-with-expanded-syntax-caching-evaluator ...0:0
                               ??? [5]                                        100.0%
------------------------------------------------------------------------------------
                               call-with-expanded-syntax-caching-evaluator [4]100.0%
 [5]    1(0.0%)     0(0.0%)  ??? ...lects/racket/private/more-scheme.rkt:261:28
                               run-module-instance! [6]                       100.0%
------------------------------------------------------------------------------------
                               ??? [5]                                        100.0%
 [6]    1(0.0%)     0(0.0%)  run-module-instance! (unknown source)
                               for-loop [7]                                   100.0%
------------------------------------------------------------------------------------
                               run-module-instance! [6]                       100.0%
 [7]    1(0.0%)     0(0.0%)  for-loop (unknown source)
                               temp35_0 [8]                                   100.0%
------------------------------------------------------------------------------------
                               for-loop [7]                                   100.0%
 [8]    1(0.0%)     0(0.0%)  temp35_0 (unknown source)
                               [running body] [9]                             100.0%
------------------------------------------------------------------------------------
                               temp35_0 [8]                                   100.0%
 [9]    1(0.0%)     0(0.0%)  [running body] ...ane/Code/ado/src/server.rkt":##f
                               profile-thunk [10]                             100.0%
------------------------------------------------------------------------------------
                               [running body] [9]                             100.0%
[10]    1(0.0%)     0(0.0%)  profile-thunk ...are/pkgs/profile-lib/main.rkt:9:0
                               run [11]                                       100.0%
------------------------------------------------------------------------------------
                               profile-thunk [10]                             100.0%
[11]    1(0.0%)     0(0.0%)  run ...t v7.6/share/pkgs/profile-lib/main.rkt:39:2
                               temp2 [12]                                     100.0%
------------------------------------------------------------------------------------
                               run [11]                                       100.0%
[12]    1(0.0%)     1(0.0%)  temp2 /Users/shane/Code/ado/src/server.rkt:12:15
------------------------------------------------------------------------------------
@zyrolasting
Copy link
Owner

zyrolasting commented Jun 17, 2020

Thanks for raising this. The contracts are not checking complicated structures, although one of them does consult the filesystem. I'm not sure if that would cause a CPU spike.

The profile actually alerted me to a loop that spins when it should be yielding time to other threads. I'll just need to rewrite some code to better leverage synchronizeable events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants