Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

All your files have been destroyed (sorry). Paul.


programming / comp.lang.smalltalk.dolphin / Fastest way to update 20,000+ game objects position?

SubjectAuthor
* Fastest way to update 20,000+ game objects position?Zenchess
+- Re: Fastest way to update 20,000+ game objects position?Sergio Del Franco
`* Re: Fastest way to update 20,000+ game objects position?Bruno Buzzi Brassesco
 `* Re: Fastest way to update 20,000+ game objects position?Zenchess
  `* Re: Fastest way to update 20,000+ game objects position?john.a...@gmail.com
   `* Re: Fastest way to update 20,000+ game objects position?Bruno Buzzi Brassesco
    `* Re: Fastest way to update 20,000+ game objects position?Ala'a Alawi
     `* Re: Fastest way to update 20,000+ game objects position?Zenchess
      `* Re: Fastest way to update 20,000+ game objects position?john.a...@gmail.com
       `* Re: Fastest way to update 20,000+ game objects position?Zenchess
        `- Re: Fastest way to update 20,000+ game objects position?john.a...@gmail.com

1
Subject: Fastest way to update 20,000+ game objects position?
From: Zenchess
Newsgroups: comp.lang.smalltalk.dolphin
Date: Thu, 3 Sep 2020 03:40 UTC
X-Received: by 2002:a37:638d:: with SMTP id x135mr1303521qkb.60.1599104404580;
Wed, 02 Sep 2020 20:40:04 -0700 (PDT)
X-Received: by 2002:a4a:4fd0:: with SMTP id c199mr113662oob.54.1599104404434;
Wed, 02 Sep 2020 20:40:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Wed, 2 Sep 2020 20:40:04 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2600:8804:1205:ed00:bd32:28dc:d1e8:310e;
posting-account=r2EEkwoAAADz3M0x3Szspui4wqseZF5h
NNTP-Posting-Host: 2600:8804:1205:ed00:bd32:28dc:d1e8:310e
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
Subject: Fastest way to update 20,000+ game objects position?
From: zench...@gmail.com (Zenchess)
Injection-Date: Thu, 03 Sep 2020 03:40:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
  Hi, I wrote an external interfacing wrapper for Raylib, and duplicated their BunnyMark demo.  I was surprised that I could spawn far less bunnies without a lot of FPS drop.  After some profiling, it turned out that updating the positions of each bunny by += velocity was taking a very long time, something like 50+ms on 20,000 objects. 

  What would be the fastest way to do this just inside dolphin?  I know that the theoretical fastest way would probably be to write a c++ library to do it.

  The way I was doing it was I had bunny objects, with points for position and velocity.  They were stored in an OrderedCollection, and then a do:[:each| each position: each position + each velocity].

  I know very little about optimization in Smalltalk so I would appreciate any advice on this topic, thanks - Jacob


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Sergio Del Franco
Newsgroups: comp.lang.smalltalk.dolphin
Date: Fri, 4 Sep 2020 16:03 UTC
References: 1
X-Received: by 2002:a0c:bd02:: with SMTP id m2mr1608113qvg.0.1599235434961;
Fri, 04 Sep 2020 09:03:54 -0700 (PDT)
X-Received: by 2002:aca:c5c7:: with SMTP id v190mr1774235oif.37.1599235434495;
Fri, 04 Sep 2020 09:03:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Fri, 4 Sep 2020 09:03:53 -0700 (PDT)
In-Reply-To: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=191.84.213.9; posting-account=yLVg6AoAAACEisDROzJKbF3TKjCK_524
NNTP-Posting-Host: 191.84.213.9
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a8accace-2a07-4991-a0ad-4bb117e2384an@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: sdelfra...@gmail.com (Sergio Del Franco)
Injection-Date: Fri, 04 Sep 2020 16:03:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
El Thursday, September 3, 2020 a la(s) 12:40:05 AM UTC-3, Zenchess escribió:
Hi, I wrote an external interfacing wrapper for Raylib, and duplicated their BunnyMark demo. I was surprised that I could spawn far less bunnies without a lot of FPS drop. After some profiling, it turned out that updating the positions of each bunny by += velocity was taking a very long time, something like 50+ms on 20,000 objects.
What would be the fastest way to do this just inside dolphin? I know that the theoretical fastest way would probably be to write a c++ library to do it.
The way I was doing it was I had bunny objects, with points for position and velocity. They were stored in an OrderedCollection, and then a do:[:each| each position: each position + each velocity].
I know very little about optimization in Smalltalk so I would appreciate any advice on this topic, thanks - Jacob

The profiler should help you find where the problem is.
E.g.:
[BunnyMarkDemo run] profile.
Then select the sample set in the first tab and analize the information the last four tabs. As this is your first time, I recommend you to start by the last one, "Time".


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Bruno Buzzi Brassesc
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 7 Sep 2020 17:02 UTC
References: 1
X-Received: by 2002:a05:620a:7f6:: with SMTP id k22mr19835766qkk.337.1599498172114;
Mon, 07 Sep 2020 10:02:52 -0700 (PDT)
X-Received: by 2002:aca:3255:: with SMTP id y82mr128833oiy.87.1599498171729;
Mon, 07 Sep 2020 10:02:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 7 Sep 2020 10:02:51 -0700 (PDT)
In-Reply-To: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=186.53.85.50; posting-account=9bXKwQoAAABPQazYnK93PaH66oPYo6yw
NNTP-Posting-Host: 186.53.85.50
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: bruno.br...@gmail.com (Bruno Buzzi Brassesco)
Injection-Date: Mon, 07 Sep 2020 17:02:52 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Hi,

Did you take a look at:
https://www.youtube.com/watch?v=NiJWcQJseLQ
https://www.youtube.com/watch?v=nIb9rmxJ4Ko
https://www.youtube.com/watch?v=_6Obmt0hGh4
https://www.youtube.com/watch?v=koOsS-vD-XA

For all simulations you have to create a subclass od DoubleBufferedView (or maybe create your own DoubleBufferedView).

regards,
bruno


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Zenchess
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 04:54 UTC
References: 1 2
X-Received: by 2002:aed:26a1:: with SMTP id q30mr23712027qtd.25.1599540846530;
Mon, 07 Sep 2020 21:54:06 -0700 (PDT)
X-Received: by 2002:a4a:8504:: with SMTP id k4mr17268133ooh.79.1599540846300;
Mon, 07 Sep 2020 21:54:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Mon, 7 Sep 2020 21:54:06 -0700 (PDT)
In-Reply-To: <d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2600:8804:1205:ed00:ad38:6f8c:6a96:3ab2;
posting-account=r2EEkwoAAADz3M0x3Szspui4wqseZF5h
NNTP-Posting-Host: 2600:8804:1205:ed00:ad38:6f8c:6a96:3ab2
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com> <d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: zench...@gmail.com (Zenchess)
Injection-Date: Tue, 08 Sep 2020 04:54:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Yes, I've already been rendering games with opengl.  I'm using GLFW to create the window, not dolphin. 
The problem isn't a rendering issue - it's that running the code I gave above takes a very long time to execute. 

Here is an example code that illustrates the issue a := OrderedCollection new.

1 to: 20000 do: [:count|
  a add: (2@2)].

Time millisecondsToRun: [
 1 to: 20000 do: [:index|
   (a at: index) x: index]
]

would give like 50-80 ms to run the second block.


  This is not the exact code in my update loop, but basically I am updating the position of 20,000 or so game objects every frame and it's taking around 50-80 ms to run code like the above.  I was just seeing if there is a more performant way of updating a large number of objects in dolphin, i.e. perhaps I shouldnt use a class at all for my game objects, and store everything in an array, an orderedCollection, I'm not really sure. 


Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.a...@gmail.com
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 07:17 UTC
References: 1 2 3
X-Received: by 2002:a37:6393:: with SMTP id x141mr22085225qkb.238.1599549458073;
Tue, 08 Sep 2020 00:17:38 -0700 (PDT)
X-Received: by 2002:aca:c5c7:: with SMTP id v190mr1741351oif.37.1599549457739;
Tue, 08 Sep 2020 00:17:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 00:17:37 -0700 (PDT)
In-Reply-To: <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=85.203.70.180; posting-account=OQ6sIwoAAAC1iWrFEUhdmRsgEkeDOgOm
NNTP-Posting-Host: 85.203.70.180
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
<d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.asp...@gmail.com (john.a...@gmail.com)
Injection-Date: Tue, 08 Sep 2020 07:17:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
What's the spec of your machine? For me your test code runs in 4ms - this is in Windows 10 running under VMWare on a 10 year old Mac, so probably not especially performant by today's standards.

I'd second the suggestion of running a test in the Profiler to highlight any hotspots in your code.


On Tuesday, September 8, 2020 at 5:54:07 AM UTC+1, Zenchess wrote:
Yes, I've already been rendering games with opengl. I'm using GLFW to create the window, not dolphin.
The problem isn't a rendering issue - it's that running the code I gave above takes a very long time to execute.

Here is an example code that illustrates the issue a := OrderedCollection new.

1 to: 20000 do: [:count|
a add: (2@2)].

Time millisecondsToRun: [
1 to: 20000 do: [:index|
(a at: index) x: index]
]

would give like 50-80 ms to run the second block.


This is not the exact code in my update loop, but basically I am updating the position of 20,000 or so game objects every frame and it's taking around 50-80 ms to run code like the above. I was just seeing if there is a more performant way of updating a large number of objects in dolphin, i.e. perhaps I shouldnt use a class at all for my game objects, and store everything in an array, an orderedCollection, I'm not really sure.


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Bruno Buzzi Brassesc
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 11:41 UTC
References: 1 2 3 4
X-Received: by 2002:ad4:4891:: with SMTP id bv17mr754670qvb.27.1599565262372; Tue, 08 Sep 2020 04:41:02 -0700 (PDT)
X-Received: by 2002:a9d:191e:: with SMTP id j30mr13242336ota.51.1599565262064; Tue, 08 Sep 2020 04:41:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.etla.org!news.uzoreto.com!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 04:41:01 -0700 (PDT)
In-Reply-To: <195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=186.53.7.162; posting-account=9bXKwQoAAABPQazYnK93PaH66oPYo6yw
NNTP-Posting-Host: 186.53.7.162
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com> <d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com> <195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: bruno.br...@gmail.com (Bruno Buzzi Brassesco)
Injection-Date: Tue, 08 Sep 2020 11:41:02 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 17
View all headers
a := OrderedCollection new.
1 to: 20000 do: [:count|
a add: (2@2)].

Time millisecondsToRun: [
1 to: 20000 do: [:index|
(a at: index) x: index]
]

would give like 50-80 ms to run the second block.

In my machine run in 2 millisecods.

What version of Dolphin are you using ?
Also as John asked which hardware do you have in your machine ?

regards,
bruno


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Ala'a Alawi
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 17:39 UTC
References: 1 2 3 4 5
X-Received: by 2002:a05:620a:222:: with SMTP id u2mr1135172qkm.218.1599586771674;
Tue, 08 Sep 2020 10:39:31 -0700 (PDT)
X-Received: by 2002:a9d:4d01:: with SMTP id n1mr129140otf.294.1599586771332;
Tue, 08 Sep 2020 10:39:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 10:39:31 -0700 (PDT)
In-Reply-To: <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=217.165.188.172; posting-account=mkOgdwoAAAAGDUBcY0S_1Gob1TR-ZY2T
NNTP-Posting-Host: 217.165.188.172
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
<d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
<195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com> <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: amal...@gmail.com (Ala'a Alawi)
Injection-Date: Tue, 08 Sep 2020 17:39:31 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Is it milli or micro seconds? I maybe reading something wrong

On Tuesday, September 8, 2020 at 3:41:02 PM UTC+4, Bruno Buzzi Brassesco wrote:
a := OrderedCollection new.
1 to: 20000 do: [:count|
a add: (2@2)].

Time millisecondsToRun: [
1 to: 20000 do: [:index|
(a at: index) x: index]
]

would give like 50-80 ms to run the second block.

In my machine run in 2 millisecods.

What version of Dolphin are you using ?
Also as John asked which hardware do you have in your machine ?

regards,
bruno



Subject: Re: Fastest way to update 20,000+ game objects position?
From: Zenchess
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 22:55 UTC
References: 1 2 3 4 5 6
X-Received: by 2002:ac8:3902:: with SMTP id s2mr725454qtb.258.1599605747433;
Tue, 08 Sep 2020 15:55:47 -0700 (PDT)
X-Received: by 2002:a9d:58c8:: with SMTP id s8mr1004173oth.292.1599605747157;
Tue, 08 Sep 2020 15:55:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Tue, 8 Sep 2020 15:55:46 -0700 (PDT)
In-Reply-To: <cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2600:8804:1205:ed00:3cce:fde2:86cc:e28f;
posting-account=r2EEkwoAAADz3M0x3Szspui4wqseZF5h
NNTP-Posting-Host: 2600:8804:1205:ed00:3cce:fde2:86cc:e28f
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
<d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
<195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com> <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
<cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dcf09d8f-69a4-4261-b4e0-9e94de76e7c2n@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: zench...@gmail.com (Zenchess)
Injection-Date: Tue, 08 Sep 2020 22:55:47 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2803
X-Received-Body-CRC: 567571906
View all headers

Sorry about that, that wasn't actually the code that was taking a while, actually what I was doing in my code was:
Object subclass: #Bunny
instanceVariableNames: 'position speed color'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

(accessors for position, speed and color)

bunnies := OrderedCollection new.
1 to: 20000 do: [:index| |bunny|
bunny := Bunny new position: 200@200;  speed: 5@5;yourself.
bunnies add: bunny.
].


and then my game loop would need to call the below to update them once per frame (of course I wasn't using time millisecondsToRun to run during the actual game loop)


Time millisecondsToRun:[bunnies do: [:each|
each position: each position + each speed.
((each position x + (32)) > 800) | ((each position x + 32) < 0) ifTrue: [each speed x: each speed x* -1].
(each position y + (32)) > height  | ((each position y + 32) < 0) ifTrue: [each speed y: each speed y* -1].
]].

which takes 13 milliseconds on my dolphin (my processor is an i7 7700k).
However when I profiled the same code in c++ it would only take about 200 microseconds.

Anyway, thanks for the responses, I will check the profiler in dolphin to see if I can optimize this.


Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.a...@gmail.com
Newsgroups: comp.lang.smalltalk.dolphin
Date: Wed, 9 Sep 2020 08:02 UTC
References: 1 2 3 4 5 6 7
X-Received: by 2002:a37:97c6:: with SMTP id z189mr2249697qkd.74.1599638520782; Wed, 09 Sep 2020 01:02:00 -0700 (PDT)
X-Received: by 2002:a9d:386:: with SMTP id f6mr2008612otf.348.1599638520476; Wed, 09 Sep 2020 01:02:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Wed, 9 Sep 2020 01:02:00 -0700 (PDT)
In-Reply-To: <dcf09d8f-69a4-4261-b4e0-9e94de76e7c2n@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=85.203.70.180; posting-account=OQ6sIwoAAAC1iWrFEUhdmRsgEkeDOgOm
NNTP-Posting-Host: 85.203.70.180
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com> <d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com> <195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com> <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com> <cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com> <dcf09d8f-69a4-4261-b4e0-9e94de76e7c2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <74faf940-d7c7-4b72-bdc5-73b1c5d2d81dn@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.asp...@gmail.com (john.a...@gmail.com)
Injection-Date: Wed, 09 Sep 2020 08:02:00 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 66
View all headers
Dolphin is interpreted so will always be slower than a compiled language. This paper is rather old but still worth reading on the pros, cons and philosophy behind Dolphin's interpreter:

http://www.object-arts.com/downloads/papers/TheInterpreterIsDead.PDF

As a further comparison, running your test code in Pharo (JIT compiled) takes 2ms, compared to 18ms in Dolphin on my machine (I've changed the undefined 'height' for 800 in order to run the code).

In terms of optimisation, the Point arithmetic (position + speed) appears to be the main hotspot, possibly down to creating a new object. Reworking this to directly modify the existing position as follows:

each position x: each position x + each speed x.
each position y: each position y + each speed y.

....brings my runtime down to 12ms. This can be slightly reduced further (and the code tidied) by implementing a method in Point to do this:

moveBy: aPoint

x := x + aPoint x.
y := y + aPoint y

The test code then becomes:

each position moveBy: each speed.

....and runtime is 11ms.

A further optimisation is to use the shortcutting form of or: [..] instead of | in the conditional checks:

(((each position x + (32)) > 800) or: [(each position x + 32) < 0]) ifTrue: [each speed x: each speed x* -1].
(((each position y + (32)) > 800) or: [(each position y + 32) < 0]) ifTrue: [each speed y: each speed y* -1].

My final runtime is then 8ms.

HTH.

John



On Tuesday, September 8, 2020 at 11:55:48 PM UTC+1, Zenchess wrote:
Sorry about that, that wasn't actually the code that was taking a while, actually what I was doing in my code was:
Object subclass: #Bunny
instanceVariableNames: 'position speed color'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

(accessors for position, speed and color)

bunnies := OrderedCollection new.
1 to: 20000 do: [:index| |bunny|
bunny := Bunny new position: 200@200; speed: 5@5;yourself.
bunnies add: bunny.
].


and then my game loop would need to call the below to update them once per frame (of course I wasn't using time millisecondsToRun to run during the actual game loop)


Time millisecondsToRun:[bunnies do: [:each|
each position: each position + each speed.
((each position x + (32)) > 800) | ((each position x + 32) < 0) ifTrue: [each speed x: each speed x* -1].
(each position y + (32)) > height | ((each position y + 32) < 0) ifTrue: [each speed y: each speed y* -1].
]].

which takes 13 milliseconds on my dolphin (my processor is an i7 7700k).
However when I profiled the same code in c++ it would only take about 200 microseconds.

Anyway, thanks for the responses, I will check the profiler in dolphin to see if I can optimize this.


Subject: Re: Fastest way to update 20,000+ game objects position?
From: Zenchess
Newsgroups: comp.lang.smalltalk.dolphin
Date: Thu, 10 Sep 2020 04:53 UTC
References: 1 2 3 4 5 6 7 8
X-Received: by 2002:ac8:3fd4:: with SMTP id v20mr6154828qtk.210.1599713620247;
Wed, 09 Sep 2020 21:53:40 -0700 (PDT)
X-Received: by 2002:a9d:315:: with SMTP id 21mr2990321otv.278.1599713619992;
Wed, 09 Sep 2020 21:53:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Wed, 9 Sep 2020 21:53:39 -0700 (PDT)
In-Reply-To: <74faf940-d7c7-4b72-bdc5-73b1c5d2d81dn@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2600:8804:1205:ed00:4c6:29a7:95af:2ef3;
posting-account=r2EEkwoAAADz3M0x3Szspui4wqseZF5h
NNTP-Posting-Host: 2600:8804:1205:ed00:4c6:29a7:95af:2ef3
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
<d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
<195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com> <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
<cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com> <dcf09d8f-69a4-4261-b4e0-9e94de76e7c2n@googlegroups.com>
<74faf940-d7c7-4b72-bdc5-73b1c5d2d81dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <31f8b9aa-0457-414a-b75b-4e6910e7786an@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: zench...@gmail.com (Zenchess)
Injection-Date: Thu, 10 Sep 2020 04:53:40 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Thanks John.  Do you think there is a way to further optimize it, for example not using points, or some other different way of structuring the data? 
Optimization in smalltalk is a topic I am interested in but have read nothing about as far as I remember.  Eventually I guess I will have to learn c++ better
so I can check out what is actually happening behind the scenes.


Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.a...@gmail.com
Newsgroups: comp.lang.smalltalk.dolphin
Date: Thu, 10 Sep 2020 08:15 UTC
References: 1 2 3 4 5 6 7 8 9
X-Received: by 2002:ac8:3fee:: with SMTP id v43mr6807174qtk.192.1599725744880;
Thu, 10 Sep 2020 01:15:44 -0700 (PDT)
X-Received: by 2002:a4a:de4b:: with SMTP id z11mr3592579oot.34.1599725744592;
Thu, 10 Sep 2020 01:15:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Thu, 10 Sep 2020 01:15:44 -0700 (PDT)
In-Reply-To: <31f8b9aa-0457-414a-b75b-4e6910e7786an@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=85.203.70.180; posting-account=OQ6sIwoAAAC1iWrFEUhdmRsgEkeDOgOm
NNTP-Posting-Host: 85.203.70.180
References: <71dc22f7-ed25-458c-9e16-f1e9d49aded2n@googlegroups.com>
<d46cfc3e-b83c-4e7c-9da3-97e377cfa71en@googlegroups.com> <f68642a9-41d6-4590-b570-6a1de07f5bb1n@googlegroups.com>
<195b8c69-f284-45dd-970b-bd232f3365b4n@googlegroups.com> <88463a84-b1ce-4f64-8a75-d638e75d0b2an@googlegroups.com>
<cad1560d-cbbe-407e-9d44-1790c04cbd76o@googlegroups.com> <dcf09d8f-69a4-4261-b4e0-9e94de76e7c2n@googlegroups.com>
<74faf940-d7c7-4b72-bdc5-73b1c5d2d81dn@googlegroups.com> <31f8b9aa-0457-414a-b75b-4e6910e7786an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5768286b-e4ba-4d59-a6f8-4a790baa3119n@googlegroups.com>
Subject: Re: Fastest way to update 20,000+ game objects position?
From: john.asp...@gmail.com (john.a...@gmail.com)
Injection-Date: Thu, 10 Sep 2020 08:15:44 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Nice idea. I removed the use of points, instead storing positionX, positionY, speedX and speedY directly within Bunny, and added Bunny>>moveAndCheck

moveAndCheck

        positionX := positionX + speedX.
        positionY := positionY + speedY.

        "Also remove numeric calculations here for small extra gain"
((positionX > 768) or: [positionX < -32]) ifTrue: [speedX := speedX * -1].
((positionY > 768) or: [positionY < -32]) ifTrue: [speedY := speedY * -1].

Test code then simply becomes:

Time millisecondsToRun: [bunnies do: [ :each | each moveAndCheck]].

This brings my runtime down to 4ms, the gain likely coming from the removal of a number of message sends (which are relatively expensive, as detailed in the "Interpreter is dead slow?" paper).

I'm going to stick my neck out and say this is about as fast as this code can be made to run in Dolphin, though I'd be delighted to be proved wrong!

Cheers.

John


On Thursday, September 10, 2020 at 5:53:40 AM UTC+1, Zenchess wrote:
Thanks John. Do you think there is a way to further optimize it, for example not using points, or some other different way of structuring the data?
Optimization in smalltalk is a topic I am interested in but have read nothing about as far as I remember. Eventually I guess I will have to learn c++ better
so I can check out what is actually happening behind the scenes.


1
rocksolid light 0.7.2
clearneti2ptor