Threads for amirouche

  1. 3

    Interesting slides, thanks @amirouche! I did my master thesis on an Erlang supercompiler. It can theoretically do the Futamura projections, so I’m a bit familiar with them but I had no idea they were used in practice in GraalVM. Very cool.

    I want to mention a related cool thing, which is checking properties of programs. If you have the procedure f and you want to find under which conditions it returns an even number, then you can partially evaluate (lambda (n) (even? (f n)). When doing this the program essentially runs with an abstract n argument rather than a concrete number, and the code after partial evaluation will be a new program that tells you under which conditions an even number is returned. Basically f will disappear and only those parts of it that were relevant to answering even? should remain. You’d need something like a supercompiler to get the full effect.

    1. 2

      Thanks for the pointers.

      I am going through pebook [0] and plan to apply what I learn on Kernel.

      [0] http://www.itu.dk/people/sestoft/pebook/

    1. 6

      John shutt discusses some similar ideas. He delineates a class of ‘interpreted programming languages’, in which this philosophy may be applied to ordinary application runtime (not just analysis), and classes even seeming dynamic standouts like common lisp as ‘compiled’ (contra kernel, of course). I have never been quite sure what to make of kernel, but I think that there is obviously something there, that we should be fools to discard without considering.

      1. 1

        Thanks for the link.

      1. 1

        Profile the stacks that at some point call function f.

        I do not know what profiling the stack is, help?

        When f is called with x, return f(x) but also log what the results would have been for f(x+1) and f(x-1).

        I do not understand the purpose.

        We can replace a function with an object that can be called for the exact same behavior, but also gives us an information sidechannel.

        With program reflection, you can achieve most what you want: given a function (sum function) [0] that expose at runtime the source of a function with its lexical scope (also known as static scope), and another function that I call (sink ...) that does the opposite operation.

        [0] it comes from the latin expression: dubito, ergo cogito, ergo sum. That I map as follows: dubito ~ information gathering; cogito ~ optimization; and sum ~ reflection.

        one step further than homoiconicity: instead of code as data we have programs as data.

        Exactly.

        Mind the fact, that what you describe is already possible in a limited way using manual JIT: change the behavior of a program, based on knowledge gathered, and only available at runtime when the program includes a compiler, and expose it to the user, where homoiconicity helps a lot.

        Manual JIT is in the control of the user, but requires a priori and precise knowledge of what the algorithm does. For example, a hash-table with keys only known at runtime, may be rewritten into a switch where clause are ordered by frequency.

        That is achieved with something along the line:

        (eval `(lambda (argument) ,(hash-table->switch ht)))
        

        That particular hash-table to switch transform can be constructed, and compiled at runtime in user code, and is generic enough to be shipped as a library.

        Quoting OP:

        Track the arguments for every call to an expensive function. If it’s called with the same parameters ten times, alert someone that they should be calling it once and storing the result.

        That is doable, without manual JIT.

        people raving about it never talk about “augmenting” programs in the way I’m looking for.

        If you have read until here, what do you think about:

        (sink eval (optimize (sum eval)))
        

        I don’t think there’s very much work done in this kind of dynamic analysis.

        Look into 3-lisp, John N. Shutt’s Kernel, and Nada Amin.

        TIL: test amplification. It is unclear how it works. Is it some kind of fuzzer that produce test-cases based on types?

        1. 3

          I don’t know if any of these are impossible without runtime metaprogramming, but they all seem like they’d be more difficult. At the very least you couldn’t do them from the REPL.

          Yeah, that was a weird section! 3/6 things listed are trivial to do in Lua, (just picked out of a hat as a language which I know well but isn’t typically considered cutting edge or advanced) a language without any metaprogramming whatsoever, and I can’t figure out how metaprogramming would make the others any simpler. They’re just simple applications of having first-class functions, and easy to do in the repl.

          I don’t think there’s very much work done in this kind of dynamic analysis. If there was then I’d see a lot more dynamic typing advocates talking about it or showcasing

          Maybe people just don’t think it’s that big of a deal?

          1. 4

            Maybe people just don’t think it’s that big of a deal?

            PLT is hard enough to get grants for, so my guess is that it’s far easier to fund work on static types than it is for dynamic stuff.

          2. 2

            I do not understand the purpose.

            I should probably write a separate newsletter on why exactly I want this, because I’ve struggled to explain it to other people before. The idea is to first-class the idea of a “function driver”, which I often do for GAN art and research coding anyway, but as a separate system.

            1. 2
              Profile the stacks that at some point call function f.
              

              I do not know what profiling the stack is, help?

              I imagined the goal to be understanding control flow / the call graph in order to understand potential optimizations / hoisting of expressions… I guess dynamically? Not clear to me why you wouldn’t use static analysis techniques ahead of time though. Dynamic languages still work with (at least some) static analysis algorithms…

              I’m making this guess based on the thing above that talks about “alerting someone” that there’s a hot function. Which… I’m not sure why you wouldn’t do profiling / benchmarking to obtain that, especially since it talks of alerting someone … e.g. it’s not dynamically rewriting the code.

              I do not understand the purpose.

              I’ll admit that I’m stumped by this too. One might imagine that a general logger for function calls might be useful in certain situations (and there’s no real reason it can’t also be done in staticly typed languages, mind you), but “speculative” execution of x+1, x-1 seems not very general purpose.


              To be quite honest, I’m having trouble understanding why this all needs to be done at runtime, and not with the existing tooling we have today: profilers, debuggers, benchmarks, etc.. Sure, I guess it might be nice to have an interpreter “trace” mode that can automatically glean information, sift through it, and provide value. But:

              1. Some JITs are already advanced enough to hot path optimizations
              2. You wouldn’t run this tracing mode in production (and so, you still need to find some way to exercise the system to generate meaningful traces before production)
              3. None of this seems impossible to do today, either directly in code with first class functions or with external tools.

              Even the “drop into a debugger on uncaught exception” could be done in many languages with a shell script (provided tests can be run in the debugger).

              But if all these things are possible, why aren’t they done? Why is Rails moving away from metaprogramming magic? Why isn’t Language Oriented Programming (e.g. DSLs, Macros) more prevalent? It’s because people “sell simplicity” as a silver bullet, in lieu of more understanding.

              The complaints about Rails metaprogramming have always been: “When it breaks, I have no idea how to fix it?” Which is sort of like saying: “I’m a status quo engineer who isn’t willing to look past the fact that I have no clue how my tools work.” But this is valid, because most people are 9-5ers who just want to mine the quarry mindlessly. (And even the people curious enough to understand some of their tools can’t understand all of them)

              The complaints about DSLs / Macros have always been: “Now I have to learn multiple languages. Why are you doing this to me?” But this is also valid, because most people do not understand language fundamentals enough to not need a 400 page O’Reilly book to pick up a new language. It’s also valid because most people don’t actually know how to write good languages (or regular APIs for that matter).

              E.g. we’re collectively not very good at any of this, and everything is far too complex for even the best engineers to fully understand.

              Those that are, those that attempt to pave new roads to programmer enlightenment don’t also have the skills to lead people, en masse, to it, so it ends up being in a paper / blog post / talk that a subset of people nod their head to, and then move on.

              1. 2

                To be quite honest, I’m having trouble understanding why this all needs to be done at runtime, and not with the existing tooling we have today: profilers, debuggers, benchmarks, etc.

                We could even say that these tools are “post-run-time”. I like that. We need to improve post-runtime tooling.

            1. 11

              it looks intersting but the the crypto bro part immediately turned me off

              1. 9

                Our company has nothing to do with cryptocurrencies! We’re building HVM, a massively parallel functional runtime developed in Rust, based on a new model of computation (Interaction Nets), that is outperforming Haskell’s compiler in some cases by an order of magnitude. I believe it is a groundbreaking technology that has the potential to change the tech industry by making massive parallelism accessible. It is the first “automatic parallelization” project with remarkable real-world success and numbers to back it up.

                Yes, we’re building a p2p computer too, but it is just a secondary product we made mostly to showoff the performance of the HVM. Specifically, we replaced Ethereum’s EVM by the HVM, and managed to hit ~100x increased throughput for many opcodes. But that’s just it, a p2p virtual machine. It isn’t cryptocurrency. It doesn’t even have a currency! I share the hate, but not every p2p project is a cryptocurrency. Torrent and DNS existed way before Bitcoin, and are fundamental to the internet as we know it!

                That said, this webpage is a draft and we’re due to some massive rework of it, because it is clearly not showing our intents properly, so that’s not your fault. We need to communicate better.

                1. 2

                  I would be very interested a p2p computer. I think having a shared computer with state is a key building block for a lot of services. I’m also interested in replicating the experience/vibe of having a shared machine that multiple (trusted) people can SSH into. No interest in having money involved here.

                  1. 2

                    Exactly! That’s the spirit/point of our chain: you do NOT need a cryptocurrency to have a worldwide shared computer, and such a thing would be so useful as a technological primitive that projects can rely on, just like internet protocols and whatnot. But I’m almost regretting developing it because people immediately jump to the conclusion that we’re a crypto project, even though the chain isn’t nearly as important as HVM and don’t even have a currency!

                    1. 4

                      Don’t call it a chain IMO. That nearly lost my interest when I saw it.

                      1. 2

                        To be clear, does the chain use proof-of-work or other energy-wasting mechanisms?

                    2. 2

                      If you don’t want people to think it’s a cryptocurrency thing, you badly need to redesign the marketing. The very first thing I see when I look at this is a picture of a chain. You’ve already turned off everyone who dislikes cryptocurrency at this point.

                      The fact that there’s text on that next page that says it’s not a cryptocurrency thing doesn’t help you much because you already created a bad first impression and some readers have already left by this point.

                      A second problem I have is this:

                      It is PoW-based, forever. In fact, PoS isn’t even possible, since there is no built-in currency.

                      This is one of the specific aspects of cryptocurrencies that has made people dislike them.

                      Could you not cut out the PoW waste entirely by having some TTPs sign blocks, acting like notaries?

                    3. 5

                      Looks like a less banana-pants crazy variation on the Urbit idea.

                      1. 4

                        to be clear the parts that look interesting to me are Kind2 and HVM

                        1. 1

                          Me too. I am also interested in the ‘Interaction Combinators’ mentioned in the manifesto. It is unclear to me how it relates to HVM. Any hint?

                          1. 1

                            HVM is the first real-world efficient implementation of Interaction Nets! We took this new model of computation, which was invented in 1997, developed a memory-efficient representation for it, called Symmetric Interaction Calculus, and, based on that, we implemented the High-order Virtual Machine (HVM), a massively parallel runtime. Right now it only targets functional languages, and it is already outperforming Haskell’s GHC by 9.2x in some cases (!), but it isn’t limited to FP.

                        1. 2

                          I am in awe of NFAI (New-Fangled AI) yet I still don’t understand how it works.

                          I don’t think practitioners of current AI really understand how it works; it’s rather a trial and error approach so far; theories on neural networks are emerging, but only on single, isolated architectures or aspects; so the use of DNN is still rather an art than a science, a blackbox which somehow does what was hoped for, or something completely different which seems also useful and provides material for a publication.

                          1. 1

                            Yes, also the “more data will make it better” is exactly the meme that killed GOFAI.

                          1. 1

                            Most of the questions I asked about performance to the creators of Berkeley DB were all along the line: it depends on your use-case, aka. YMMV. And experimenting with various databases, it is hyper clear that in all case: caveat emptor.

                            dbbench is a good tool to build a shortlist. Though, it will not replace actual use-case specific benchmarks.

                            Some things I did not foresee while experiment with several OKVS:

                            • Memory use;
                            • Memory use, when loading data in bulk;
                            • On-disk space use;
                            • Small vs. not-small keys;
                            • UUID vs. ULID;
                            • Non-monotonic increment;

                            And I did not dive into data integrity, and consistency correctness.

                            1. 4

                              A liburing based embedded database, something like SQLite or better like RockDB but with a simpler API.

                              1. 2

                                Playing around with io_uring

                                1. 2

                                  any code to share?

                                  1. 1

                                    Sure! Its not great and I’ve got a lot of improvements todo… https://github.com/ewan15/eipher

                                1. 1

                                  Porting my bash program to compile several Scheme implementations from git, and add support for the test runner I use in my chez wrapper called letloop to make it work with all of those implementations. My goal is to make it easier to create portable Scheme libraries, and programs. I already have a JSON library that runs on 10 implementations, and I want to achieve the same with the revision of SRFI-167 (okvs).

                                  1. 8

                                    $50 is hardly low-cost for a microcomputer/microcontroller, not when you can get a RPi Zero for US$5. (With a significantly higher clock speed than 18MHz…)

                                    Clearly I’m not the target market for this. But wouldn’t a true retro fetishist be taken aback that this board has an ESP32 (32-bit SoC) on it, running the display? Sort of like the dad holding the baby on his lap letting it pretend to drive…

                                    1. 2

                                      from https://www.thebyteattic.com/p/about.html

                                      I focus on 8-bit computers because my kick is innovative, elegant computer architecture, not performance. Therefore, the number of bits is rather irrelevant to me, and I choose 8 bits because the architecture and design effort aren’t smothered by massive data and address buses.

                                      and

                                      I’ve found that only now, as a hobbyist, did I finally manage to do the kind of creative engineering work I dreamed of as a 17-year-old freshman in engineering school.

                                      so this is about passion, not efficiency

                                      1. 1

                                        I’m not sure why they conflate the two categories. $50 is okay for a microcomputer – they really are selling something that is more like a ZX Spectrum, and I’d definitely pay $50 for that – but definitely not… anywhere near okay for a microcontroller. I’m pretty sure you can get a $50 development board for a microcontroller.

                                        The Pi Zero is one tenth of that but you basically get an underpowered phone running Linux in some mysterious manner. $50 for an open source board with open source software (no idea if these claims are true, mind you!) that’s basically a beefed up Sinclair isn’t bad.

                                        I can’t say I ever fell in love with the Pis for small hacks – it always felt like I spent two days putting a cool hack together, and another day or so dealing with systemd, Samba or NFS shennanigans, and God knows what else. I’d gladly pay $50 for something that takes me to a BASIC prompt and lets me peek and poke things instead of asking me to install some weird Python library with fifty Github stars which only works on Python 3.4.2. I’ve given up on cool ideas I had in an afternoon more than once just because, by the time I managed to put together a working image, it was eight in the evening and I had boring grown-up shit to do.

                                        The true retro fetishist will probably scoff at things like Flash memory, too, but then again, if they’re tru retro, they can just get an actual ZX Sinclair :-).

                                        1. 1

                                          $20 ESP32 boards are nice if you don’t want a big OS getting in your way. They can be coded either like Arduinos or in full C/++ with a bigger library.

                                          If you want a friendlier language there are a lot of boards that have MicroPython built in, making them super easy to start writing code for. Installing other Python libs can be annoying but that’s not a fair comparison with BASIC, where you’re limited to the features and commands that come with it.

                                          1. 3

                                            ESP32 is not floss.

                                            1. 2

                                              I am proooobably not the best person to talk to about the ESP32, either :-(. Maybe it’s because I come from an embedded background – working with these things is kind of my job, so I don’t have a lot of patience when doing it as a hobby. I love things that are either really good embedded development platforms – good documentation including schematics, lots of pins and few hoops to jump through for interfacing, lots of test pads, hardware that’s easy to debug, good cross-compiler support that shield you as little as possible from the underlying hardware, good JTAG interfacing etc. – or really good computers, like, I dunno, the Mega65.

                                              In my experience – but admittedly, that was years ago, when it was far less popular – the ESP32s were neither. It took a lot of fiddling to get them to work, and when they didn’t, you had to dig through a lot of magic to figure out why. Lots of times it boiled down to libraries stepping on each others’ toes, or to bugs in their HAL.

                                              I don’t mind a large language or OS However, I would really love a hobby platform that requires less fiddling than a “pro” platform, with the understanding that, sure, it’s not going to be as flexible, or maybe really not as capable. Most “maker”-category boards I tried require a comparable amount of fiddling, for about the same capabilities (if you’re willing to forgo the Arduino or MicroPython bits) or less, modulo weird design choices made in order to meet specific size requirements or manufacturing constraints.

                                              Mind you, I haven’t tried this board. But I’ve often seen the Pi marketed from a similar angle – something supposed to make computing fun again, something you can just plug in and use, like you could do with the BBC Micro or the Spectrum decades ago. Frankly, if the Spectrum, my first computer, would’ve been as annoying as a Pi or an ESP32, I probably would’ve chosen a very different career path :-D. From the specs, this looks far closer to the “modern reinterpretation of classical microcomputers” view.

                                              1. 2

                                                Yeah, MicroPython (and its for fork CircuitPython) really blew me away with how immediate & accessible it is, and reminded me a lot of the BASIC days. A Raspberry Pi Pico can boot directly into python, and that seems like a better, smaller, cheaper equivalent to this Agon.

                                          1. 1

                                            What is kernel mode setting and DRM?

                                            1. 2

                                              By the way of Wikipedia leading paragraphs

                                              DRM is Direct Rendering Manager:

                                              The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations such as configuring the mode setting of the display. DRM was first developed as the kernel-space component of the X Server Direct Rendering Infrastructure, but since then it has been used by other graphic stack alternatives such as Wayland.

                                              User-space programs can use the DRM API to command the GPU to do hardware-accelerated 3D rendering and video decoding, as well as GPGPU computing.

                                              https://en.wikipedia.org/wiki/Direct_Rendering_Manager

                                              KMS is Kernel Mode Setting:

                                              Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer’s display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).

                                              The display mode is set by the kernel. In user-space mode-setting (UMS), the display mode is set by a user-space process.

                                              Kernel mode-setting is more flexible and allows displaying of an error in the case of a fatal system error in the kernel, even when using a user-space display server.

                                              User-space mode setting would require superuser privileges for direct hardware access, so kernel-based mode setting shuns such requirement for the user-space graphics server.

                                              https://en.wikipedia.org/wiki/Mode_setting

                                            1. 2

                                              Very inspiring project. It shows how a limited set of available features can stir creativity, just in line with the other retro, and fantasy consoles.

                                                1. 2

                                                  Custom protocol to communicate with DB. It’s same category as rqlite but worst because now you have to implement protocol as well.

                                                1. 1

                                                  Working on my first take to solve the “micro-libraries” problem !

                                                  1. 3

                                                    Wandering aimlessly.

                                                    1. 2

                                                      Do you know a stone program that allows to compare other benchmark results?

                                                      (Millions of writes per seconds looks like a lot)

                                                      1. 1

                                                        At https://docs.python.org/3/library/ctypes.html?highlight=ctypes#loading-shared-libraries one can read:

                                                        The Python global interpreter lock is released before calling any function exported by these libraries, and reacquired afterwards.

                                                        Cython also has a nogil keyword.

                                                        If we can generalize: any C foreign function call with release the CPython GIL, then one can scale SQLite better than the algorithm that is described in the linked article. A hint is that gunicorn used to recommend for synchronous workers 2 * nproc - 1 threads per CPython interpreter.

                                                        It seems to me Janus dependency is not necessary, async with app.database_write_mutex(): out = await app.transaction(func) may be enough.

                                                        1. 1

                                                          Thanks for the write mutex tip, I’ll look into that.

                                                          I actually had some success with the nogil Python getting SQL queries to run in parallel recently - I wrote about that here: https://simonwillison.net/2022/May/6/weeknotes/

                                                        1. 11

                                                          There’s another package called cdb.

                                                          1. 1

                                                            Came here to say this. Hopefully, the more people upvote this, the op will reconsider the name.

                                                            1. 4

                                                              I don’t mind changing the name at all! I didn’t expect this project to take off and get noticed by many. On reddit and here, name thing has been brought up already, so I am definitely considering to rename it.

                                                              1. 2

                                                                It ack’ed in the README:

                                                                Name

                                                                cdb is an acronym for Cask Database, and it is not related to D. J. Bernstein’s cdb. I don’t expect this to get popular or used in production environments, and naming things is hard pleading_face.

                                                                https://github.com/avinassh/cdb#name

                                                                1. 6

                                                                  I will never understand the obsession with naming things that aren’t user logins or executable files three characters long. “Cask DB” is a wonderful name for the project.

                                                                  1. 5

                                                                    hey, thank you for the feedback. I wasn’t expecting this to be noticed by many, so I just kept it as cdb. It also refers to an internal joke between me and my partner.

                                                                    I am considering to rename it

                                                                    1. 2

                                                                      I’d encourage you to rename it. cdb is a well-recognized name for djb’s project and since yours is fairly fresh, it’d be a good thing to not create an ambiguity, especially if you are aware of it. If nothing else, it will prevent any discussion of your work to veer immediately to this subject at the expense of the rest. Just like it did here.

                                                                      1. 5

                                                                        If nothing else, it will prevent any discussion of your work to veer immediately to this subject at the expense of the rest. Just like it did here.

                                                                        This is a great point. I have renamed it to py-caskdb and I have also credited your message.

                                                            1. 1

                                                              Thanks for sharing. You might be interested in my project called LBST [0] to implement sorted kv.

                                                              [0] https://github.com/amirouche/lbst

                                                              1. 2

                                                                wow, this looks interesting, thanks for sharing! This is much closer to D. J. Bernstein’s constant db.