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

Allow tree shaking of the core environment when it is unobservable. #478

Closed
wants to merge 1 commit into from

Conversation

andrewchambers
Copy link
Member

We can avoid loading the full core environment if the mutable
parts of core are not reachable from the main function. This
is quite a large number of programs.

This change makes 'hello world' 2-3 times faster, and uses approximately
10 times less ram.

We can avoid loading the full core environment if the mutable
parts of core are not reachable from the main function. This
is quite a large number of programs.

This change makes 'hello world' 2-3 times faster, and uses approximately
10 times less ram.
@andrewchambers
Copy link
Member Author

I feel this approach could be improved/altered with any of:

  • A jpm option for this.
  • Tweaks to the C code in peg, such that it does not take things directly from the root-env.

@bakpakin
Copy link
Member

bakpakin commented Oct 7, 2020

I like this idea a lot, and rather than implement hacks to get around certain issues, I think it might be worth considering changing the core library to avoid any calls (directly or indirectly) janet_core_env in all cfunctions.

@bakpakin
Copy link
Member

bakpakin commented Dec 4, 2020

BTW, this draft is not dead, just pending changes to the thread module, which seem to be the biggest hurdle in adding the functionality. , It is currently quite difficult to remove any references to the janet_core_env function in the thread module.

bakpakin added a commit that referenced this pull request Jan 23, 2021
Add --no-core option to quickbin, as well as :no-core option
to declare executable. This doesn't use the autodetection when
making binaries, instead opting for manual intervention.
@bakpakin
Copy link
Member

bakpakin commented Jan 24, 2021

The commits I have added have taken some of the code from here, but reworked. Mainly, we don't use the auto-dectection since there are cases where the auto-detection can fail, say when loading a native module that tries to use janet_dobytes at module load time. Other than that, it seems to be working well, and definitely cuts down start time for hello, world!

Example usage:

# hello.janet
(defn main [&] (print "hello, world!"))

With core library disabled:

$ jpm --no-core quickbin hello.janet hello
generating executable c source...
compiling hello.c to build/hello.o...
linking hello...
$ time ./hello
hello, world!

real	0m0.001s
user	0m0.001s
sys	0m0.000s

Without core library disabled:

$ jpm quickbin hello.janet hello2
generating executable c source...
compiling hello2.c to build/hello2.o...
linking hello2...
$ time ./hello2
hello, world!

real	0m0.003s
user	0m0.003s
sys	0m0.000s

@bakpakin bakpakin closed this Jan 24, 2021
@sogaiu
Copy link
Contributor

sogaiu commented Jan 24, 2021

Here are some local results:

$ jpm --no-core quickbin hello.janet hello
generating executable c source...
compiling hello.c to build/hello.o...
linking hello...

$ multitime -n10 -s1 ./hello
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
===> multitime results
1: ./hello
            Mean        Std.Dev.    Min         Median      Max
real        0.003       0.002       0.001       0.003       0.006       
user        0.001       0.001       0.000       0.001       0.003       
sys         0.002       0.002       0.000       0.002       0.006       

$ jpm quickbin hello.janet hello2
generating executable c source...
compiling hello2.c to build/hello2.o...
linking hello2...

$ multitime -n10 -s1 ./hello2
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
hello, world!
===> multitime results
1: ./hello2
            Mean        Std.Dev.    Min         Median      Max
real        0.008       0.007       0.002       0.004       0.020       
user        0.006       0.006       0.000       0.003       0.016       
sys         0.002       0.002       0.000       0.003       0.004       

@andrewchambers
Copy link
Member Author

nice, thanks, it should be useful for programs like jfmt.

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

Successfully merging this pull request may close these issues.

None yet

3 participants