caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: <becker.nils@gmx.net>
To: caml-list@inria.fr
Subject: [Caml-list] using React for -- reactions
Date: Tue, 19 Aug 2014 10:34:59 +0200	[thread overview]
Message-ID: <sympa.1408436986.28320.956@inria.fr> (raw)

hi,

i am looking for performance advice in the context of an event driven
simulation using react.ml. in a nutshell: can a React-based simulation
scheme be made similarly fast as an imperative scheme which mutates
arrays in-place? is there a run-time cost for large dependency graphs?

specifically:

i am exploring doing a Gillespie-type simulation for a network of
chemical reactions using React. here is how it looks. there are N
species and R possible reactions between them. each chemical species has
an associated molecule number signal. each reaction has an associated
event. the event triggers updates of the number signals of the
reaction's input and output species; this is implemented using E.select
and S.accum. the waiting time to the next reaction event of any of the R
reactions is a (random) function of the molecule numbers of its inputs;
after the molecule numbers are updated, the waiting times for all
affected reactions are updated using E.merge. the waiting times for
future events are managed in a separate heap. to initiate the next
update step, the earliest scheduled waiting time is popped from the
heap, and the associated reaction event is started.

reactions are relatively sparse, ie. the number of reactions R=O(N),
where N could be from 1e1 to 1e4 or so. so, in each update step only a
small number <10 of dependent molecule numbers and waiting times need to
be updated, even for large systems. in other words, the React-managed
dependency graph is wide (N) but not tall (relatively short dependecy
chains, see above), and it has some lateral connections. (side note, it would
be helpful to be able to output the graph somehow for debugging purposes)

when profiling, i find that indeed the runtime for a fixed number of
steps does not increase much as N increases. this is good. most of the
time seems to be spent within the H.up and H.down functions in React,
not in the random number generation. this is not ideal since it
indicates dependency handling overhead. (correct?)

for small N, the simulation runs about 10x slower than an
alternative version which instead of using React, keeps molecule numbers
in lists and functionally updates the list manually in each step.

the list version scales linearly with N, which disqualifies it; but i
think that a 'classical' version that stores molecule numbers in an
array would solve that problem. the reason i would still prefer a React
based scheme is that this would allow to dynamically update the network
of reactions at runtime, allowing for flexible, extensible rule-based
simulation.

bottom line: can a React based simulation possibly compete with manual,
in-place update of arrays, let's say within a factor of 2? if yes what
do i need to pay attention to?

             reply	other threads:[~2014-08-19  8:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19  8:34 becker.nils [this message]
2014-08-19 12:27 ` Daniel Bünzli
2014-08-19 13:13   ` Nils Becker
2014-08-20  9:11   ` Nils Becker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sympa.1408436986.28320.956@inria.fr \
    --to=becker.nils@gmx.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).