From: Dmitry Antipov <dmantipov@yandex.ru>
To: emacs-devel@gnu.org
Subject: Re: Using empty_string as the only "" string
Date: Thu, 26 Apr 2007 18:24:01 +0400 [thread overview]
Message-ID: <4630B601.2040602@yandex.ru> (raw)
In-Reply-To: <jwv8xchisdd.fsf-monnier+emacs@gnu.org>
Stefan Monnier wrote:
> PS: But if you're interested in such small optimizations, I have another one
> in my local Emacs where the Lisp_String data type is changed to:
>
> struct Lisp_String
> {
> EMACS_INT size;
> EMACS_INT size_byte : BITS_PER_EMACS_INT - 1;
> unsigned inlined : 1; /* 0 -> ptr, 1 -> chars; in union below. */
> INTERVAL intervals; /* text properties in this string */
> union
> {
> unsigned char *ptr;
> unsigned char chars[STRING_MAXINLINE];
> } data;
> };
>
> this way, on 32bit systems, strings of up to 3 bytes can be represented with
> just a Lisp_String without any `sdata'. On 64bit systems, this can be used
> for strings up to 7 bytes long (i.e. almost 50% of all allocated strings,
> IIRC). And it can also be used for all the strings in the pure space (no
> matter how long), so it saves about 50KB of pure space (can't remember the
> exact number, but IIRC it was more than 10KB and less than 100KB).
I'm interesting in _any_ optimization. Here is a brain-damaged :-) Lisp_String
I'm thinking about:
#define STRING_IMMEDIATE_SIZE (sizeof (EMACS_INT) * 3 - 2)
struct Lisp_String
{
union
{
/* Immediate string. */
struct
{
unsigned immediate : 1;
unsigned gcmarkbit : 1;
unsigned size : BITS_PER_CHAR - 1;
unsigned size_byte : BITS_PER_CHAR - 1;
unsigned char data[STRING_IMMEDIATE_SIZE];
} __attribute__ ((packed)) imm;
/* Contains pointer to sdata. */
struct
{
unsigned immediate : 1;
unsigned gcmarkbit : 1;
unsigned size : BITS_PER_EMACS_INT - 1;
unsigned size_byte : BITS_PER_EMACS_INT - 1;
unsigned char *data;
} __attribute__ ((packed)) dat;
} u;
INTERVAL intervals; /* text properties in this string */
};
This gives 9-byte "immediate" string on 32-bit and 21-byte on 64-bit (excluding
trailing '\0'). This is not suitable for long pure strings, btw.
Strictly speaking, this is not an optimization - it saves space at the (minimal ?)
cost of speed since the most of string operations involves extra conditional
expression at least. For example,
#define STRING_BYTES(STR) ((STR)->size_byte < 0 ? (STR)->size : (STR)->size_byte)
becomes (over?)complicated
#define __IMM_P(STR) ((STR)->u.imm.immediate)
#define __IMMSIZE(STR) ((STR)->u.imm.size_byte < 0 ? (STR)->u.imm.size : (STR)->u.imm.size_byte)
#define __DATSIZE(STR) ((STR)->u.dat.size_byte < 0 ? (STR)->u.dat.size : (STR)->u.dat.size_byte)
#define STRING_BYTES(STR) (__IMM_P (STR) ? __IMMSIZE (str) : __DATSIZE (STR))
Dmitry
next prev parent reply other threads:[~2007-04-26 14:24 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-24 16:32 Using empty_string as the only "" string Dmitry Antipov
2007-04-24 17:05 ` Juanma Barranquero
2007-04-24 18:11 ` Andreas Schwab
2007-04-24 18:50 ` Juanma Barranquero
2007-04-24 21:38 ` Andreas Schwab
2007-04-24 21:54 ` Juanma Barranquero
2007-04-24 22:11 ` Andreas Schwab
2007-04-24 22:54 ` Juanma Barranquero
2007-04-24 21:57 ` David Kastrup
2007-04-24 22:07 ` Lennart Borgman (gmail)
2007-04-24 22:29 ` David Kastrup
2007-04-24 22:35 ` Andreas Schwab
2007-04-25 0:55 ` Kenichi Handa
2007-04-25 9:51 ` Andreas Schwab
2007-04-25 9:58 ` David Kastrup
2007-04-25 10:50 ` Andreas Schwab
2007-04-24 22:40 ` Lennart Borgman (gmail)
2007-04-24 22:12 ` Andreas Schwab
2007-04-24 22:31 ` David Kastrup
2007-04-24 22:56 ` Andreas Schwab
2007-04-24 21:39 ` Miles Bader
2007-04-24 21:45 ` Juanma Barranquero
2007-04-24 22:11 ` Miles Bader
2007-04-24 22:59 ` Juanma Barranquero
2007-04-24 23:37 ` Miles Bader
2007-04-24 23:44 ` Johan Bockgård
2007-04-25 1:47 ` Miles Bader
2007-04-25 14:52 ` Richard Stallman
2007-04-26 15:03 ` Daniel Brockman
2007-04-27 20:40 ` Richard Stallman
2007-04-25 2:05 ` Richard Stallman
2007-04-25 12:00 ` Juanma Barranquero
2007-04-25 2:05 ` Richard Stallman
2007-04-24 17:48 ` Stefan Monnier
2007-04-25 2:05 ` Richard Stallman
2007-04-26 14:24 ` Dmitry Antipov [this message]
2007-04-25 2:05 ` Richard Stallman
-- strict thread matches above, loose matches on Subject: below --
2007-04-25 5:38 using " dmantipov
2007-04-25 5:49 ` Miles Bader
2007-04-25 11:50 ` Juanma Barranquero
2007-04-25 11:56 ` Kenichi Handa
2007-04-25 13:22 ` Dmitry Antipov
2007-04-25 16:07 ` Stefan Monnier
2007-04-26 4:23 ` Richard Stallman
2007-04-26 13:03 ` Dmitry Antipov
2007-04-27 6:00 ` Richard Stallman
2007-04-27 10:04 ` Dmitry Antipov
2007-04-27 10:29 ` David Kastrup
2007-04-28 4:06 ` Richard Stallman
2007-04-28 8:54 ` Dmitry Antipov
2007-04-28 18:35 ` Richard Stallman
2007-06-05 15:43 ` Juanma Barranquero
2007-06-05 19:17 ` Richard Stallman
2007-06-05 19:45 ` Juanma Barranquero
2007-06-06 1:17 ` Stefan Monnier
2007-06-06 11:04 ` Juanma Barranquero
2007-06-06 22:09 ` Richard Stallman
2007-06-08 15:49 ` Juanma Barranquero
2007-06-08 19:16 ` Stefan Monnier
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=4630B601.2040602@yandex.ru \
--to=dmantipov@yandex.ru \
--cc=emacs-devel@gnu.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.