Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4765 days ago | link | parent

By the way, just to show how easy it is to use the namespace system, I'll demonstrate how it's possible to load and use an Arubic library from Arc.

First off, Arubic is implemented as a namespace on top of Arc's namespace, so assuming the Arubic library is called "foo.arc", when you do this:

  > (import foo)
  nil

  > namespace
  #<namespace (len 2)>
Notice that the namespace is now length 2, because it inherits from Arc's namespace. But you don't want to use Arubic, you want to use Arc! But because of the malleability and inspectability of Nu namespaces, it's easy to fix that. Just do this:

  > (zap namespace-fn namespace rev)
  #<namespace (len 2)>
The above just reversed the order of the namespace, so now the Arc namespace inherits from the Arubic namespace, rather than vice versa.

This effectively "undoes" the changes that Arubic made, which is exactly what you want: now you can use the functions and macros defined in the Arubic library from within Arc, and everything works perfectly.



1 point by Pauan 4765 days ago | link

I just did some timing tests. As I suspected, the namespace system is quite costly in terms of performance:

  1   2      3    4    6    6    7
  0%  1732%  31%  22%  20%  17%  12%
What the above means is that when going from 1 namespace to 2, you lose 1732% of speed, meaning your code will now run ~17 times slower. But going from 2 namespaces to 3 has only a 31% drop in speed, and 3 to 4 only has 22%, etc.

What this means is that the initial hurdle of namespaces is quite large, but adding more namespaces after the 2nd is quite decent in terms of performance.

The reason for this is (ironically) speed optimizations. When executing code in the Arc namespace, I actually completely bypass the namespace system entirely, so it's relying on Racket to do global lookups, and Racket is far faster at looking up global variables than Nu is.

That's why going from 1 to 2 namespaces is so slow: Racket is so fast that when it switches to the Nu code, Nu looks horribly slow by comparison. But when going from 2 to 3 namespaces, we're already using the Nu code, so the difference in speed is tiny.

In other words, Racket is so fast it makes Nu look bad.

---

By the way, this only applies to code that is evaluated in a Nu namespace: if you evaluate everything in Arc's namespace, there's no cost in speed at all. So this drop in speed only applies while using things like Arubic, and not Arc itself.

-----