Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Forty two.


devel / comp.lang.postscript / Re: Speed or space

SubjectAuthor
* Speed or spaceDavid Newall
+- Re: Speed or spaceJohn Reiser
`* Re: Speed or spaceCarlos
 `- Re: Speed or spaceDavid Newall

1
Speed or space

<62027f03$1@news.ausics.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=140&group=comp.lang.postscript#140

  copy link   Newsgroups: comp.lang.postscript
Date: Wed, 9 Feb 2022 01:32:35 +1100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Newsgroups: comp.lang.postscript
Content-Language: en-US
From: davidn@davidnewall.com (David Newall)
Subject: Speed or space
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <62027f03$1@news.ausics.net>
Organization: Ausics - https://www.ausics.net
Lines: 29
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: David Newall - Tue, 8 Feb 2022 14:32 UTC

Still working on utf8show and have classic space vs. time tradeoff.

I can store the UnicodeEncoding map in a Dictionary, which is blindingly
fast, or in a sparse array, which is more compact but slower to access.
Every glyph painted needs a lookup in the map.

---Bytes Used-- --Savings-- -Time(ms)-- S:D ms
Map Source Dict Sparse Bytes % Dict Sparse Ratio
AdobeGlyphList(1) 222472 180798 41686 19% 161 2968 18.45
FreeSerif.gn2(2) 442320 356006 86314 20% 604 2856 4.73
UnifontMedium.gn2(3) 3357832 2173806 1184026 35% 156 949 6.08

(1) AdobeGlyphList from ghostscript v9.50 on Ubuntu 20.04.3.

(2) Generated by fontforge from FreeSerif.sfd extracted from
freefont-src-20120503.tar.gz from ftp.gnu.org/gnu/freefont.

(3) Generated by fontforge from unifont-14.0.01.ttf extracted
from unifont-14.0.01.tar.gz from ftp.gnu.org/gnu/unifont/.

Tests were performed using Ghostscript 9.5 on Ubuntu 20.04.3 with
Intel(R) Core(TM) i7-1165G7 @ 2.80GHz. Glyphs for UNICODE values 0
through 150,000 were retrieved from each map five times.

I don't know why accessing the sparse Adobe map is so much slower than
the other two. Average retrieval time is under 4ns; for UnifontMedium
it's under 1.3ns.

I'm going to implement it one way only. Which should it be?

Re: Speed or space

<Z5WdncDej45rnZn_nZ2dnUU7_83NnZ2d@giganews.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=141&group=comp.lang.postscript#141

  copy link   Newsgroups: comp.lang.postscript
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 09 Feb 2022 11:59:18 -0600
Date: Wed, 9 Feb 2022 09:59:17 -0800
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Subject: Re: Speed or space
Content-Language: en-US
Newsgroups: comp.lang.postscript
References: <62027f03$1@news.ausics.net>
From: vendor@BitWagon.com (John Reiser)
In-Reply-To: <62027f03$1@news.ausics.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <Z5WdncDej45rnZn_nZ2dnUU7_83NnZ2d@giganews.com>
Lines: 9
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-RSGM7LarNH2Y2csunlxzViG+Uw6y7cxGjoW5rnc8+TLfqgDZcWE/WKYinNNTEFYok/2OCte9M0rR/de!1Ds5gEvej8rJbON3djMn40pRtsyy03eHXBksYCXQ83jMo5MxGQImQdVvVmMsTMb8xIlgXVToMR6j
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1507
 by: John Reiser - Wed, 9 Feb 2022 17:59 UTC

On 2/8/22 06:32, David Newall wrote:
> Still working on utf8show and have classic space vs. time tradeoff.
[[snip]]
> I'm going to implement it one way only.  Which should it be?

Small space is more important than blindingly-fast. Think of containers
in the cloud, where stingy RAM allocations abound and demand paging
is horrible or impossible.

Re: Speed or space

<20220210152810.00002cff@cvkm.cz>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=144&group=comp.lang.postscript#144

  copy link   Newsgroups: comp.lang.postscript
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: carlos@cvkm.cz (Carlos)
Newsgroups: comp.lang.postscript
Subject: Re: Speed or space
Date: Thu, 10 Feb 2022 15:28:10 +0100
Lines: 45
Message-ID: <20220210152810.00002cff@cvkm.cz>
References: <62027f03$1@news.ausics.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: individual.net GM5BL85Rudoa/YUYyYKKmQ1pMGT84H9tkmFfe/NfKIYy3D81PZ
Cancel-Lock: sha1:n53KcmIFK68sXh3l21FlLMnL0mE=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.29; x86_64-w64-mingw32)
 by: Carlos - Thu, 10 Feb 2022 14:28 UTC

On Wed, 9 Feb 2022 01:32:35 +1100
David Newall <davidn@davidnewall.com> wrote:

> Still working on utf8show and have classic space vs. time tradeoff.
>
> I can store the UnicodeEncoding map in a Dictionary, which is
> blindingly fast, or in a sparse array, which is more compact but
> slower to access. Every glyph painted needs a lookup in the map.

I don't know what a sparse array is in this context. Is it like the
input array to unicodefont? In that case maybe it could be optimized,
by, idk, putting code points in entries 0, 2, 4, 6, ... to speed up
lookup, and the corresponding arrays with glyph names (or just the main
glyph name) in entries 1, 3, 5, 7, ..., or something like that.
>
> ---Bytes Used-- --Savings-- -Time(ms)-- S:D ms
> Map Source Dict Sparse Bytes % Dict Sparse Ratio
> AdobeGlyphList(1) 222472 180798 41686 19% 161 2968 18.45
> FreeSerif.gn2(2) 442320 356006 86314 20% 604 2856 4.73
> UnifontMedium.gn2(3) 3357832 2173806 1184026 35% 156 949 6.08
>
> (1) AdobeGlyphList from ghostscript v9.50 on Ubuntu 20.04.3.
>
> (2) Generated by fontforge from FreeSerif.sfd extracted from
> freefont-src-20120503.tar.gz from ftp.gnu.org/gnu/freefont.
>
> (3) Generated by fontforge from unifont-14.0.01.ttf extracted
> from unifont-14.0.01.tar.gz from ftp.gnu.org/gnu/unifont/.
>
> Tests were performed using Ghostscript 9.5 on Ubuntu 20.04.3 with
> Intel(R) Core(TM) i7-1165G7 @ 2.80GHz. Glyphs for UNICODE values 0
> through 150,000 were retrieved from each map five times.
>
> I don't know why accessing the sparse Adobe map is so much slower than
> the other two. Average retrieval time is under 4ns; for UnifontMedium
> it's under 1.3ns.
>
> I'm going to implement it one way only. Which should it be?

Contrary to John's opinion, I don't think space matters much,
especially if it's only 3 MB. So I'd choose speed. But then, I don't
know anything about Postscript printers or other low capacity devices.

C.

Re: Speed or space

<5a784437-8d6f-ff9c-1639-d742f4abd5bb@davidnewall.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=146&group=comp.lang.postscript#146

  copy link   Newsgroups: comp.lang.postscript
Message-ID: <5a784437-8d6f-ff9c-1639-d742f4abd5bb@davidnewall.com>
Date: Wed, 16 Feb 2022 14:29:57 +1100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Subject: Re: Speed or space
Content-Language: en-US
To: Carlos <carlos@cvkm.cz>
Newsgroups: comp.lang.postscript
References: <62027f03$1@news.ausics.net> <20220210152810.00002cff@cvkm.cz>
From: davidn@davidnewall.com (David Newall)
In-Reply-To: <20220210152810.00002cff@cvkm.cz>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Organization: Ausics - https://www.ausics.net
Lines: 45
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: David Newall - Wed, 16 Feb 2022 03:29 UTC

On 11/2/22 01:28, Carlos wrote:
> I don't know what a sparse array is in this context.

Thanks for your feedback and thoughts.

I deliberately chose a term that suggests the implementation without
pinning it down so that I could ask about speed vs space without getting
bogged down over how it was implemented.

Here's how I implemented it:

A "sparse" array contains values indexed by integers, and efficiently
permits missing values. Each element in the array is a sub-array
containing the index of the first value followed by one or more values.

For example: [[8 v8 v9 v10] [14 v14 v15] [37 v37]] is a sparse array
containing values at index 8, 9, 10, 14, 15 and 37.

The sparseget procedure retrieves an element from a sparse array. If
the array contains a value at that index, the value and true is pushed
on the stack, otherwise false is pushed.

I compared normal versus packed arrays and found that packing saved
negligible space while substantially increasing access time, so sparse
arrays are not packed.

In terms of performance versus a dictionary (for UnicodeEncoding map)
accessing a sparse array takes around 5 times longer, which sounds awful
but (on my computer) that's sub-1ns access versus 4ns, so I don't think
the speed is an issue.

One inexplicable result is that the sparse array generated from the
built-in AdobeGlyphList (Ghostscript 9.50 on Ubuntu 20.04 with Intel
i7-1165G7 @ 2.80Mhz) takes 25 times as long as the equivalent
dictionary. I don't understand why so much slower compared with maps
from fonts. Clutching at straws, I initially thought it might be
because AdobeGlyphList is built-in and maps from (non-builtin) fonts
aren't, but that can't be the case. For benchmarks, I load the
dictionary and sparse arrays from external files so, although derived
from the built-in dictionary, they are unlikely to be stored in common.
I also tried changing the names (added "xx" to them) and the result
stands. It's a mystery to me.

I'm inclined to go for space over speed but am willing to listen to
reason if people feel strongly that speed is more important.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor