crashappsec / crashappsec/chalk

Optimize the Chalk startup to cache the base config at compile time

Open
#26 2 comments 0 reactions 0 assignees View on GitHub
enhancement P2
Dominant language
Nim
Stars
436
Forks
25
PR merge metrics
No merged PRs in 30d

Description

There is currently a little delay when running e.g. `chalk help`, because chalk always performs various setup tasks, regardless of the user-specified command:

https://github.com/crashappsec/chalk/blob/175f32f001d90de02c3efa10d19467f08e98a1a7/src/chalk.nim#L13-L24

Does chalk want to always perform every setup task, or could it skip some of them when the command is e.g. `help`?

It's clear that `chalk help` is currently doing a lot of stuff:

```console
$ strace --summary-only --summary-columns=time-percent,calls,errors,name chalk help > /dev/null
% time calls errors syscall
------ --------- --------- ----------------
97.75 34980 read
1.00 350 lseek
0.49 106 mmap
0.45 66 munmap
0.05 15 1 rt_sigaction
0.04 6 readlink
0.04 57 getcwd
0.03 22 15 stat
0.02 5 rt_sigprocmask
0.02 11 3 ioctl
0.02 3 brk
0.02 9 lstat
0.02 13 readv
0.01 6 1 open
0.01 5 close
0.01 9 fstat
0.01 10 fcntl
0.00 6 getpid
0.00 2 writev
0.00 1 uname
0.00 1 getgid
0.00 1 getegid
0.00 1 execve
0.00 1 getuid
0.00 2 geteuid
0.00 1 getgroups
0.00 1 arch_prctl
0.00 1 set_tid_address
------ --------- --------- ----------------
100.00 35691 20 total
```

For example, `open`ing:

- `/usr/bin/docker`
- `/home/foo/.local/share/bash_completion/completions/chalk.bash`
- `/usr/local/ssl/openssl.cnf`

By the way, is this an expected number of syscalls? (I'm still new to chalk).

---

Chalk version: 175f32f001d90de02c3efa10d19467f08e98a1a7

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading src/chalk.nim lines 13-24 and reproducing `chalk help` with `strace --summary-only`. Identify which setup tasks and external paths are accessed before help runs; done means unnecessary setup is skipped for this command while its expected output remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
nim
Domain
cli, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.