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


Groups > comp.lang.c > #167171

Re: How to optimize this search?

From antispam@math.uni.wroc.pl
Newsgroups comp.lang.c
Subject Re: How to optimize this search?
Date 2022-08-23 23:54 +0000
Organization Aioe.org NNTP Server
Message-ID <te3pcd$q5o$1@gioia.aioe.org> (permalink)
References (2 earlier) <93c78669-e681-48bf-b421-ff199e5fcf7an@googlegroups.com> <d4424f70-b00d-4102-89b3-6e151cc54aa3n@googlegroups.com> <87wnayydld.fsf@nosuchdomain.example.com> <376a7c64-113a-46d3-bc81-664a6b7dd32cn@googlegroups.com> <87sflmy9qx.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> bart c <bart4858@gmail.com> writes:
> > On Tuesday, 23 August 2022 at 20:17:18 UTC+1, Keith Thompson wrote:
> [...]
> >> And that's a *lot* of "define"s. It sounds like the code you're 
> >> looking at is not typical. Your numbers don't match what I see 
> >> in the latest sqlite3 sources.
> >
> > Yeah, that looked dodgy. I don't know what's going on there. If I
> > compile only sqlite3.c, then I get more reasonable looking figures:
> >
> > 14010 define
> > 08728 if
> > 08543 int
> > 03115 endif
> > 03111 return
> > 02658 void
> > 02291 else
> >
> > Note that 10,000 of those defines are inside my windows.h. Also note
> >that the same 'if' keyword is used for "'#if".
> >
> > This is specific to normal C however. We don't know exactly what the
> > OP is doing, or what his inputs will be, whether they are already
> > preprocessed or not.
> 
> Ah, so that's 14010 occurrences of "define" after preprocessing.

Bart wrote that "define" came from "windows.h", so his input is
before preprocessing.

> The point is that if you're processing C source code and recognizing
> whether tokens that look like identifiers are keywords or not, it
> doesn't make sense to have "define" and "int" in the same table.

Why not?  Of course logically lookups for preprocessor keywords
are different from normal lookups, but there is no law that
prevent storing two logical hash tables in single physical
hash table.  In particular, info about preprocessor keywords
is likely to be quite small, so there is good chance that
you can put it in place that would be otherwise wasted by
padding.

If you want fast compiler it makes sense to do symbol
table lookup once, that is combine prepocessor with compiler.
In preprocessing stage you need to look up each identifier to
check if it is a macro, when it is not a macro you may deliver
its compilation meaninig.  Details needed for correct handling
of C are likely to be tricky and I do not know if Bart did
this correctly.  But this is clearly doable and likely to give
large speed advantage.

Note that after macros and normal C symbols are in single
table what remains is handful of preprocessor keywords.
Since they are so frequent and exclusive of normal identifiers
special purpose table may give some speed boost.  OTOH
in combined table preprocessor keywords will be entered
first, so with high probablity single lookup will work.
In other words, single combined table is likely to behave
as perfect hash for the purpose of lookup for proprocessor
keywords.  It looks tricky to come with faster alternative...

-- 
                              Waldek Hebisch

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


Thread

How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 07:17 -0700
  Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 07:34 -0700
    Re: How to optimize this search? scott@slp53.sl.home (Scott Lurndal) - 2022-08-22 16:17 +0000
      Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:24 -0700
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:38 -0700
        Re: How to optimize this search? scott@slp53.sl.home (Scott Lurndal) - 2022-08-22 17:03 +0000
        Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-23 14:58 +0300
          Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 05:02 -0700
            Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-23 17:50 +0300
              Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-23 16:58 +0100
                Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-23 19:21 +0300
                Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 09:46 -0700
                Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-23 20:06 +0300
                Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-23 23:39 +0100
                Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-24 11:20 +0300
                Re: How to optimize this search? Anton Shepelev <anton.txt@gmail.com> - 2022-08-25 00:52 +0300
                Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 23:23 +0100
                Re: How to optimize this search? Anton Shepelev <anton.txt@gmail.com> - 2022-08-26 01:38 +0300
                Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-26 00:55 +0100
                Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-26 12:02 +0300
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-26 04:10 -0700
      Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 10:47 -0700
        Re: How to optimize this search? scott@slp53.sl.home (Scott Lurndal) - 2022-08-22 18:10 +0000
          Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 15:22 -0700
            Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-22 15:37 -0700
              Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 16:28 -0700
                Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-23 01:18 +0100
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 18:01 -0700
            Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-23 00:07 +0000
              Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 18:12 -0700
                Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-23 01:54 +0000
            Re: How to optimize this search? David Brown <david.brown@hesbynett.no> - 2022-08-23 08:50 +0200
              Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 04:18 -0700
                Re: How to optimize this search? David Brown <david.brown@hesbynett.no> - 2022-08-23 15:50 +0200
      Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-22 18:51 +0000
  Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 16:34 +0100
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:14 -0700
      Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 17:33 +0100
  Re: How to optimize this search? Siri Cruise <chine.bleu@yahoo.com> - 2022-08-22 08:44 -0700
    Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 16:53 +0100
      Re: How to optimize this search? Siri Cruise <chine.bleu@yahoo.com> - 2022-08-22 09:29 -0700
        Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 17:36 +0100
    Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 16:53 +0100
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:11 -0700
      Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-22 19:30 +0000
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 14:19 -0700
          Re: How to optimize this search? Öö Tiib <ootiib@hot.ee> - 2022-08-22 14:36 -0700
          Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-22 22:49 +0000
            Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 05:13 -0700
              Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 15:55 -0700
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 16:36 -0700
                Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 17:42 -0700
                Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-23 18:36 -0700
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-24 03:34 -0700
                Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 04:40 -0700
                Re: How to optimize this search? David Brown <david.brown@hesbynett.no> - 2022-08-24 09:30 +0200
                Re: How to optimize this search? William Ahern <william@25thandClement.com> - 2022-08-24 12:36 -0700
  Re: How to optimize this search? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-22 17:51 +0200
    Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-22 16:55 +0100
    Re: How to optimize this search? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-22 18:14 +0200
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:15 -0700
      Re: How to optimize this search? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-22 18:28 +0200
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:34 -0700
          Re: How to optimize this search? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-22 18:35 +0200
            Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 09:45 -0700
              Re: How to optimize this search? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-22 18:51 +0200
              Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-23 17:53 +0300
  Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 10:20 -0700
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-22 10:53 -0700
      Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-22 23:31 +0000
        Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-22 17:04 -0700
  Re: How to optimize this search? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-08-23 09:50 -0700
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 10:07 -0700
      Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 11:28 -0700
        Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-23 12:17 -0700
          Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 13:16 -0700
          Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 13:18 -0700
            Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-23 13:23 -0700
            Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-23 13:40 -0700
              Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 16:26 -0700
                Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-23 16:50 -0700
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-23 17:26 -0700
              Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-23 23:54 +0000
                Re: How to optimize this search? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-23 17:16 -0700
                Re: How to optimize this search? David Brown <david.brown@hesbynett.no> - 2022-08-24 09:43 +0200
                Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-24 04:03 -0700
                Re: How to optimize this search? antispam@math.uni.wroc.pl - 2022-08-24 14:15 +0000
  Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 13:28 +0100
    Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 06:25 -0700
      Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 06:50 -0700
      Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 15:19 +0100
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 09:46 -0700
          Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 20:40 +0100
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 10:08 -0700
          Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 20:42 +0100
      Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-24 07:31 -0700
      Re: How to optimize this search? Anton Shepelev <anton.txt@gmail.com> - 2022-08-25 01:04 +0300
        Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 16:43 -0700
          Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 16:54 -0700
            Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-24 17:08 -0700
              Re: How to optimize this search? Anton Shepelev <anton.txt@gmail.com> - 2022-08-26 01:47 +0300
            Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-26 05:40 -0700
              Re: How to optimize this search? Thiago Adams <thiago.adams@gmail.com> - 2022-08-26 06:29 -0700
              Re: How to optimize this search? scott@slp53.sl.home (Scott Lurndal) - 2022-08-26 14:05 +0000
    Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-24 06:45 -0700
      Re: How to optimize this search? bart c <bart4858@gmail.com> - 2022-08-24 13:01 -0700
    Re: How to optimize this search? Anton Shepelev <anton.txt@gmail.com> - 2022-08-25 01:17 +0300
      Re: How to optimize this search? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 23:38 +0100
        Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-25 11:29 +0300
          Re: How to optimize this search? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-25 11:33 +0300

csiph-web