supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: Adam Joseph <adam@westernsemico.com>
To: supervision@list.skarnet.org
Subject: Re: [PATCH 2/3] s6-rc-update.c: rewrite O(n^2) loop as O(n) complexity
Date: Mon, 25 Sep 2023 17:57:44 -0700	[thread overview]
Message-ID: <169568986462.6030.10556581815632056289@localhost> (raw)
In-Reply-To: <20230926004418.24990-2-adam@westernsemico.com>

Quoting Adam Joseph (2023-09-25 17:44:17)
> The loop is O(n^2) due to the nested iteration.  We can rewrite this
> with a single iteration by making use of the invimage[] array, which
> maps from new services to old services:
> 
>    for each new service
>      if *ANY* old service converts to the new service,
>        set some new service flags based on that old service's flags
> 
> This takes advantage of the fact that invimage is an injective
> (partial) function.

As discussed on IRC, this commit touches the dependency computation routines,
which are quite delicate and (at this point) battle-tested; tampering with them
probably isn't worth the mostly-theoretical performance benefit.

I wrote this commit mainly because it seemed like there was an easy way to do
this in O(n) time, and the fact that it hadn't been done that way must mean that
I had overlooked something important.  If anybody sees an obvious mistake in
this commit, please do let me know -- it's a sign that I misunderstood
something.  Otherwise there's no need to apply this patch.

  - a

  reply	other threads:[~2023-09-26  0:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26  0:44 [PATCH 1/3] s6-rc-update.c: add #define constants for bitflags Adam Joseph
2023-09-26  0:44 ` [PATCH 2/3] s6-rc-update.c: rewrite O(n^2) loop as O(n) complexity Adam Joseph
2023-09-26  0:57   ` Adam Joseph [this message]
2023-09-26  0:44 ` [PATCH 3/3] [WIP] s6-rc-update.c: add additional comments Adam Joseph
2023-09-26  0:59   ` Adam Joseph

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=169568986462.6030.10556581815632056289@localhost \
    --to=adam@westernsemico.com \
    --cc=supervision@list.skarnet.org \
    /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).