Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.prolog > #14826

How bad is Rust, can JavaScript beat it? (Was: Scryer Prolog unify_with_occurs_check/2 doesn't scale)

From Mild Shock <janburse@fastmail.fm>
Newsgroups comp.lang.prolog
Subject How bad is Rust, can JavaScript beat it? (Was: Scryer Prolog unify_with_occurs_check/2 doesn't scale)
Date 2025-09-19 16:18 +0200
Message-ID <10ajonh$k606$1@solani.org> (permalink)
References <107t0fi$6bgl$1@solani.org> <10ajo4u$k5kc$1@solani.org>

Show all headers | View raw


Hi,

Not sure whether its a language issue, or an
algorithmic issue. But was working hard to
bring unlimited stacks to Dogelog Player,

removing the use of native stacks, and introducing
some agenda data structures for certain primitive
built-ins. Now amazingly I get in Rust:

/* Scryer Prolog 0.9.4-656 */
?- between(7,10,K), N is 4^K, test2(N), fail; true.
    % CPU time: 0.001s, 56 inferences
    % CPU time: 0.004s, 56 inferences
    % CPU time: 0.019s, 56 inferences
    % CPU time: 0.132s, 56 inferences
    true.

On the the other hand JavaScript shows me:

/* Dogelog Player 2.1.1 / Node.js v24.6.0 */
?- between(7,10,K), N is 4^K, test2(N), fail; true.
% Zeit 1 ms, GC 0 ms, Lips 15000, Uhr 19.09.2025 09:17
% Zeit 4 ms, GC 0 ms, Lips 3750, Uhr 19.09.2025 09:17
% Zeit 21 ms, GC 0 ms, Lips 714, Uhr 19.09.2025 09:17
% Zeit 57 ms, GC 0 ms, Lips 263, Uhr 19.09.2025 09:17
true.

Stunning! The test case is the same hydra as
below, now benchmarking the predicate (==)/2:

test2(N) :- hydra(N, X), hydra(N, Y, Y), time(X == Y).

But I have to redo the tests with more iterations
to flatten the erractic behaviour of time measurement
garbage collection and who nows what. Could get a

better picture. But I observe since yesterady that
JavaScript easily beats Rust, when using the Bart
Demoen folklore trick inside JavaScript. One of

the big brakes was not the stack, there is practically
no difference between using a native stack or an
artificial stack based on Array(). Its more that

the slowdown was Map(), and it could be removed
by using Bart Demoen folklore trick, as referenced
by SWI-Prolog in the source code of unify().

Bye

Mild Shock schrieb:
> Hi,
> 
> Since some idiots blocked me on Scryer Prolog issues,
> I raise the issue here. Basically uniy_with_occurs_check/2
> probably does use a different implementation of unification
> 
> than find for (=)/2. Because it doesn't scale, I find:
> 
> /* Scryer Prolog */
> ?- test3(25).
>     % CPU time: 0.001s, 57 inferences
>     true.
> 
> ?- test4(25).
>     % CPU time: 2.133s, 57 inferences
>     true.
> 
> Expectation would be that unify_with_occurs_check/2
> does just scale like it does in SWI-Prolog. In
> SWI-Prolog I find:
> 
> /* SWI-Prolog 9.3.30 */
> ?- test3(25).
> % -1 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
> true.
> 
> ?- test4(25).
> % -1 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
> true.
> 
> The test case was simply a hydra variant. Actually the
> last hydra modification posted by @kuniaki, which I
> am currently ticking along now:
> 
> hydra(0, _) :- !.
> hydra(N, h(X, X)):- N>0, N0 is N-1, hydra(N0, X).
> 
> hydra(0, A, A) :- !.
> hydra(N, h(X, X), A):- N>0, N0 is N-1, hydra(N0, X, A).
> 
> test3(N) :- hydra(N, X), hydra(N, Y, Y),
>     time(X = Y).
> 
> test4(N) :- hydra(N, X), hydra(N, Y, Y),
>     time(unify_with_occurs_check(X, Y)).
> 
> But of course there is a cut (!) in the first rules.
> 
> Mild Shock schrieb:
>> Hi,
>>
>> WebPL is already outdated I guess. It doesn't
>> show the versions of the other Prolog systems
>> it is using. While I had these results for
>>
>> the primes example in the WebPL playground:
>>
>> /* Trealla Prolog WASM */
>> (23568.9ms)
>>
>> When I run the example here:
>>
>> https://php.energy/trealla.html
>>
>> I get better results:
>>
>> /* trealla-js 0.27.1 */
>>
>> ?- time(test).
>> % Time elapsed 9.907s, 11263917 Inferences, 1.137 MLips
>>
>> Bye
> 

Back to comp.lang.prolog | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

WebPL is already outdated Mild Shock <janburse@fastmail.fm> - 2025-08-17 18:37 +0200
  Heap/Stack versus WAM resp. ZIP (Was: WebPL is already outdated) Mild Shock <janburse@fastmail.fm> - 2025-08-18 14:52 +0200
    Trealla knows Program Sharing (PS) Tricks ? (Was: Heap/Stack versus WAM resp. ZIP) Mild Shock <janburse@fastmail.fm> - 2025-08-18 15:06 +0200
      Smarter Partial Strings would use Program Sharing ['$append'/3] (Was: Trealla knows Program Sharing (PS) Tricks ?) Mild Shock <janburse@fastmail.fm> - 2025-08-18 15:42 +0200
        Static Shunting is even better [Dogelog Player] (Was: Smarter Partial Strings would use Program Sharing ['$append'/3]) Mild Shock <janburse@fastmail.fm> - 2025-08-18 15:49 +0200
  The Artificial Intelligence Flip: Acer Swift Go! (Was: WebPL is already outdated) Mild Shock <janburse@fastmail.fm> - 2025-08-31 23:56 +0200
    2025 will be last year we hear of Python (Re: The Artificial Intelligence Flip: Acer Swift Go!) Mild Shock <janburse@fastmail.fm> - 2025-09-01 00:45 +0200
      Apertus: With love, from Switzerland [02 Sept 2025] (Re: 2025 will be last year we hear of Python) Mild Shock <janburse@fastmail.fm> - 2025-09-05 00:36 +0100
      Don't try this (Was: Apertus: With love, from Switzerland [02 Sept 2025] ) Mild Shock <janburse@fastmail.fm> - 2025-09-05 01:03 +0100
      AI means ambracing Non-Linearity (Was: 2025 will be last year we hear of Python) Mild Shock <janburse@fastmail.fm> - 2025-09-19 10:01 +0200
        AI soaked PCs: Is there a Copilot+ Prolog? (Was: AI means ambracing Non-Linearity) Mild Shock <janburse@fastmail.fm> - 2025-09-19 10:10 +0200
          The morning coffee incident [Prolog Community] (Was: AI soaked PCs: Is there a Copilot+ Prolog?) Mild Shock <janburse@fastmail.fm> - 2025-09-19 14:38 +0200
            Root Cause Prediction for Your Brain (Was: The morning coffee incident [Prolog Community]) Mild Shock <janburse@fastmail.fm> - 2025-09-19 18:22 +0200
              Please delete my account and all my posts on SWI-Prolog discourse (Re: Root Cause Prediction for Your Brain) Mild Shock <janburse@fastmail.fm> - 2025-09-19 18:38 +0200
                I will consult a Lawyer of mine (Was: Please delete my account and all my posts on SWI-Prolog discourse) Mild Shock <janburse@fastmail.fm> - 2025-09-19 18:42 +0200
  Scryer Prolog unify_with_occurs_check/2 doesn't scale (Was: WebPL is already outdated) Mild Shock <janburse@fastmail.fm> - 2025-09-19 16:08 +0200
    How bad is Rust, can JavaScript beat it? (Was: Scryer Prolog unify_with_occurs_check/2 doesn't scale) Mild Shock <janburse@fastmail.fm> - 2025-09-19 16:18 +0200
    unify_with_occurs_check/2 might have been fixed (Was: Scryer Prolog unify_with_occurs_check/2 doesn't scale) Mild Shock <janburse@fastmail.fm> - 2025-09-25 01:50 +0200
      Had to Rollback my Jaffar Unification (Was: unify_with_occurs_check/2 might have been fixed) Mild Shock <janburse@fastmail.fm> - 2025-09-25 01:59 +0200
        Trealla Prolog might apply "frozeness" to cyclic terms (Was: Had to Rollback my Jaffar Unification) Mild Shock <janburse@fastmail.fm> - 2025-09-25 02:06 +0200
          Non-intrusive through "frozen" subcategories (Was: Trealla Prolog might apply "frozeness" to cyclic terms) Mild Shock <janburse@fastmail.fm> - 2025-09-25 02:21 +0200
    Scryer Prolog occurs check cannot do hydra (Was: Scryer Prolog unify_with_occurs_check/2 doesn't scale) Mild Shock <janburse@fastmail.fm> - 2025-09-26 12:19 +0200
  WebPL and Scryer Prolog are bad examples (Was: WebPL is already outdated) Mild Shock <janburse@fastmail.fm> - 2025-10-13 09:49 +0200
    Who will win Shift-Reduce or Tabled DCG? [AI Boom] (Was: WebPL and Scryer Prolog are bad examples) Mild Shock <janburse@fastmail.fm> - 2025-10-13 15:09 +0200
  primes.pl mainly tests the Prolog ALU [mod/2 vs rem/2] (Was: WebPL is already outdated) Mild Shock <janburse@fastmail.fm> - 2025-10-15 02:38 +0200
    25-30% is insane, Neural Network Branch Prediction? (Was: primes.pl mainly tests the Prolog ALU) Mild Shock <janburse@fastmail.fm> - 2025-10-15 04:33 +0200
      NPUs (Neural Processing Units) are the new normal (Was: 25-30% is insane, Neural Network Branch Prediction?) Mild Shock <janburse@fastmail.fm> - 2025-10-15 16:04 +0200
        Ask Phind: AI inflection point right now [End 2025] (Was: NPUs (Neural Processing Units) are the new normal) Mild Shock <janburse@fastmail.fm> - 2025-10-15 16:10 +0200
          Eat Tteokbokki before SkyNet kills you [$100 ChatGPT] (Was: Ask Phind: AI inflection point right now [End 2025]) Mild Shock <janburse@fastmail.fm> - 2025-10-18 15:57 +0200
            Give Julio Di Egidio the bloody money [3 RMB¥ MiniMind] (Re: Eat Tteokbokki before SkyNet kills you [$100 ChatGPT]) Mild Shock <janburse@fastmail.fm> - 2025-10-18 16:19 +0200
              Vertex AI Training is more expensive? (Was: Give Julio Di Egidio the bloody money [3 RMB¥ MiniMind]) Mild Shock <janburse@fastmail.fm> - 2025-10-21 00:32 +0200
        The Love Affair: OpenAI and AMD (Was: NPUs (Neural Processing Units) are the new normal) Mild Shock <janburse@fastmail.fm> - 2025-10-18 18:59 +0200
        The NPU in your Browser [WebNN by W3C] (Was: NPUs (Neural Processing Units) are the new normal) Mild Shock <janburse@fastmail.fm> - 2025-10-26 08:39 +0100
          Fuzzy Alert: Boris the Loris on the Dancefloor (Was: The NPU in your Browser [WebNN by W3C]) Mild Shock <janburse@fastmail.fm> - 2025-10-26 11:33 +0100

csiph-web