2 comments

  • drob5183 hours ago
    From the article:<p>&gt; I was later surprised all the real world find implementations I examined use tree-walk interpreters instead.<p>I’m not sure why this would be surprising. The find utility is totally dominated by disk IOPS. The interpretation performance of find conditions is totally swamped by reading stuff from disk. So, keep it simple and just use a tree-walk interpreter.
    • Someone1 hour ago
      Is it truly simpler to do that? A separate “command line to byte codes” module would be way easier to test than one that also does the work, including making any necessary syscalls.<p>Also, decreasing CPU usage many not speed up <i>find</i> (much), but it would leave more time for running other processes.
      • drob5181 hour ago
        If it was easier to interpret byte codes, nobody would use a tree-walk interpreter. There’s no performance reason to use a tree-walk interpreter. They all do it because it’s easy. You basically already have the expression in tree form, regardless of where you end up. So, stop processing the tree and just interpret it.
      • maxbond1 hour ago
        File operations are a good candidate for testing with side effects since they ship with every OS and are not very expensive in a tmpfs, but you don&#x27;t have to let it perform side effects. You could pass the eval function a delegate which it calls methods on to perform side effects and pass in a mocked delegate during testing.
    • chubot2 hours ago
      Yeah that&#x27;s basically what was discussed here: <a href="https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;xz6fwz&#x2F;unix_find_expressions_compiled_bytecode" rel="nofollow">https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;xz6fwz&#x2F;unix_find_expressions_compiled_by...</a><p>And then I pointed to this article on databases: <a href="https:&#x2F;&#x2F;notes.eatonphil.com&#x2F;2023-09-21-how-do-databases-execute-expressions.html" rel="nofollow">https:&#x2F;&#x2F;notes.eatonphil.com&#x2F;2023-09-21-how-do-databases-exec...</a><p>Even MySQL, Duck DB, and Cockroach DB apparently use tree-walking to evaluate expressions, not bytecode!<p>Probably for the same reason - many parts are dominated by I&#x2F;O, so the work on optimization goes elsewhere<p>And MySQL is a super-mature codebase
      • drob51856 minutes ago
        I was just reading a paper about compiling SQL queries (actually about a fast compilation technique that allows for full compilation to machine code that is suitable for SQL and WASM): <a href="https:&#x2F;&#x2F;dl.acm.org&#x2F;doi&#x2F;pdf&#x2F;10.1145&#x2F;3485513" rel="nofollow">https:&#x2F;&#x2F;dl.acm.org&#x2F;doi&#x2F;pdf&#x2F;10.1145&#x2F;3485513</a><p>Sounds like many DBs do some level of compilation for complex queries. I suspect this is because SQL has primitives that actually compute things (e.g. aggregations, sorts, etc.). But find does basically none of that. Find is completely IO-bound.
  • tasty_freeze6 hours ago
    That is a fun exercise, but I imagine the time to evaluate the conditional expression is a tiny fraction, just a percent or less, than the time it takes to make the file system calls.
    • nasretdinov5 hours ago
      For many cases you don&#x27;t even need to make stat() call to determine whether or not the file is a directory (d_type specifically can tell it: <a href="https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man3&#x2F;readdir.3.html" rel="nofollow">https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man3&#x2F;readdir.3.html</a>). That&#x27;s what allows find(1) to be so quick
      • loeg2 hours ago
        You could imagine determining from the parsed expression whether or not stat&#x27;ing was required.<p>NFS has readdirplus, but I don&#x27;t think it ever made its way into Linux&#x2F;POSIX. (Some filesystems could efficiently return dirents + stat information.)
        • nasretdinov1 hour ago
          &gt; readdirplus<p>Well, it definitely does _something_, because on NFS the subsequent stat() calls after reading the directory names do indeed complete instantly :), at least in my testing.
          • loeg1 hour ago
            I mean, readdirplus as a local filesystem API. Ultimately unix programs are just invoking getdents() (or equivalent) + stat() (or statx, whatever). Linux nfsclient probably caches the result of readdirplus for subsequent stat.
    • CerryuDu5 hours ago
      ... not to mention the time it takes to load directory entries and inodes when the cache is cold.