Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Speed of memblocks

Author
Message
Jambo B
11
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 30th Jan 2021 10:41
Hello all.

I'm writing some code that needs to run as fast as possible, and using MemBlock commands. I wondered if someone who had experience with this could advise on which commands could slow things down.

These are the commands I'm using:

GetMemblockExists
CreateMemblock
SetMemblockInt
CopyMemblock
CreateImageFromMemblock
DeleteMemblock

Are any of these particularly slow?

Thanks,

James
n00bstar
17
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 30th Jan 2021 18:27
All of them. Absolutely all of them. If you write the word "memblock" on a Ferrari, it can't go above 20km/h anymore. If you somehow fall of a plane, just scream "MEMBLOCK!" real loud before you hit the ground and you should be able to land safely.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
Scraggle
Moderator
18
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Jan 2021 18:48 Edited at: 30th Jan 2021 18:49
Memblocks themselves aren't slow.
However, when using memblocks you will inevitably need to loop through the bytes and it's the loops in AppGameKit that are slow.
Jambo B
11
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 30th Jan 2021 23:18
@n00bstar - loved that analogy - cheers for the big grin! Brilliant!

@scraggle - thanks for that, I hadn't even considered that looping might be a bottleneck, you've given me a lot to think about there.

Thanks again, both,

James
Jack
16
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 30th Jan 2021 23:25
Jambo,

if you are in Tier1,
create a plugin that can create a memblock and do the calcs on a second thread then send the result memblock pointer back and some sort of boolean that says, if writing of the second thread into memblock memory data is finished - create some sort of async operation for best speed.

Kevin Picone
18
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 31st Jan 2021 04:10
All functions calls have call overhead, regardless of what they do. This is amplified by the AppGameKit VM/Runtimes.. Some operations have higher cost due to complexity, such as creating an image from a memblock (decoded it as a texture) isn't going to be quick and there's not much you can about it. For stuff like applying operations to memblock data, pixel by pixel for example, then there's many strategies you can use to reduce the cost per pixel ( call overhead / loop overhead/ precalcs). But they're not pretty.


Quote: "

GetMemblockExists
CreateMemblock
SetMemblockInt
CopyMemblock
CreateImageFromMemblock
DeleteMemblock

"


You can run through and do brute force timer tests for these functions, but really a better idea is try and design a solution that fits what commands are available. I suspect you're trying to encrypt image data, running through each pixel altering it in some what, then writing it back. Now what you could do, is grab the source image and dump it out as pool of strips/chunks. Where there's a map of strips are uses to recreate what original source image(s). Like a dictionary, but for pixel data. Then you can use copy to move blocks pixels. This fits in better with the AppGameKit runtime and will produce images that even though might still be BMP/PNG or whatever, they aren't easily used.



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
smerf
16
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 31st Jan 2021 09:59 Edited at: 31st Jan 2021 18:34
Not sure if this is usefull or not haven't looked to deep into it

https://forum.thegamecreators.com/thread/221911

[MOD EDIT] Turned the 'link' into a clickable link. It's been 15 years Smerf, you should know how to do that by now.

Lol I'll go with the excuse that I suffer from a rare form of color blindness and cannot see the color blue

jd_zoo
3
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 31st Jan 2021 14:04
Quote: "If you somehow fall of a plane, just scream "MEMBLOCK!" real loud before you hit the ground and you should be able to land safely."


Too funny
atomcraft
User Offline
Joined: 22nd Jan 2021
Location:
Posted: 2nd Feb 2021 10:52
Commands - in general - are very slow in AppGameKit, because they have to pass a lot of tests for cross compatibility - so use them sparingly !

Consider following speed test example :



So - bottom line - as already mentioned above - use AppGameKit commands only if necessary and try to do the rest through standard variable declarations.

Jambo B
11
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 4th Feb 2021 16:27
Thank you all for your brilliant and informative posts. Much appreciated.

@atomcraft - I'd often wondered about this!!

James
janbo
12
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Feb 2021 17:48
Hi Jambo, I like you name
bye !!!!!



just kidding i actually have something to say that could roughly fit here.
So loops are defenately your enemy in AppGameKit, but i also found out that if you want to insert into an array with a custom datatype that has manny sub variable datatype thingys in it and you create a temp Variable with the same big Datatype, allocating this datatype inside any kind of loop is a really bad idea ^^
So what I did for my Voxel Engine where I have to rebuild the chuncks mesh with memblocks for every block that I place or remove is that I create a global temp variable to work on and insert into my array which Is either passed by reference or is a global.
haliop787
1
Years of Service
User Offline
Joined: 22nd Mar 2020
Playing: With reality.
Posted: 5th Feb 2021 04:26
What i do iis creating alot of lists.
Than i sort and find them, most of the times it really helps.
Only problem with sort, is that it can sort or find only the first var in any kind of Type that is attached to the array.
Nadav "Haliop" Rosenberg
Lets make the world great forever.
n00bstar
17
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 5th Feb 2021 12:40
Quote: "
Only problem with sort, is that it can sort or find only the first var in any kind of Type that is attached to the array.
"


When I need a type to be sortable by more than one variable, I usually just include a Sort variable as the first one. Then when I need to sort it, I just run a quick for/next and copy my target variable into the Sort one, and sort it from there. It doesn't help one bit for speed, but it's certainly convenient.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
JasonPC
6
Years of Service
User Offline
Joined: 14th Apr 2015
Location: United Kingdom
Posted: 5th Feb 2021 16:03
A few weeks ago, I posted for some help on the FB group.
I needed to create a thread-safe BMP loader. I created code to load the BMP file format, insert into a memblock and then create an image from the memblock.
The decode/insert was pretty quick, but running from a state machine meant I could control how long it took from my game loop. (i need to load images in the game loop and a 1080p image was taking too long).

Sadly, the "createimagefrommemblock" took as long as just loadimage....

I don't know how much optimisation the AppGameKit compiler apples, but certainly benchmark all you can. Some things did surprised me, but the createimagefrommemblock was a threadlocker and the result is that I need to just use smaller images.

One members suggestion was to use smaller images into sprites and position them together. That is an option - I don't think I need to do that, but it's there.
haliop787
1
Years of Service
User Offline
Joined: 22nd Mar 2020
Playing: With reality.
Posted: 7th Feb 2021 14:43
JasonPc turning a full hd image into 4 or 8 smaller ones are not that hard.
you simply create a renderImage of just parts of the bigger image or use normal memblocks to do so
and then just add them together after the decoder with several sprites, its an automatic function once you write it.. then just copy paste where ever needed.
a simple function isThisImgDevidedInMemblock(imgId as integer) // or something alike if so this will work if not it will just do it normal wise.

actually there is no real need to use memblocks at all to encrypt decrypt images especially if the loop is too slow to decrypt them...
you can use normal image loading, just make a mess in the image and clear it up after it is loaded.

so like some atlas images of your entire source images just in a few messy files of images (Atlas Images) where pixel 1x1 at 1X 1Y is actually 25X and 76Y at another image.
AGK can build these pretty quickly using render to image, with that said it will also give you a feel like all images are done for this Specific Phone.

1. all source images should be bigger then the highest res phone you are gonna use.
2. all source images will be divided into Atlas Images and then build them up at startup (No MEMBLOCKS NEEDED)
3. all divided source images will be rendered at "Higher resolution" on a Perfect Match Width and Height RenderImage according to the current device you are holding

n00bStar wow I WONDER why i did not thought of it. that is a genius solution. I am presuming you are using a String as it faces everything with a simple str(Float\Int) value and can be checked accordingly. that is really smart. Thank you for that.
I Uselly just create multiple lists where each one is using a different Type of the same Types just Vars inside that types are reorganized.

Well.. Your solution is much easier. however if i have 1000 objects of a type and i want to sort it by the 3rd var, i should first run trough 1000 objects turn the 3rd var insert it into the "sort String Var" and then use Sort. and Find. however you still need to use 1000 iterations which is slow... can you please elaborate how you do it ?
CreateRenderImage(GetMAxDeviceWidth(),getMaxDeviceHEight(),0,0) // etc...

Memblocks are cool when it comes to C++ (Tier 2) i think there are some plugins from Tier 2 C++ where it comes to iterating a memblock apparently using those are a faster way to process Memblocks in Tier 1 Looping etc..

Actually thinking of it.
I Think all Tier 1 users needs a C++ plugin to insert a Type inside (Object) and run trough it and manipulate the results using Tier 1 Basic code. Wonder if that is possible.
on the other hand, you can simply turn any data into IMAGE and then throw this image into a Plugin. (However i am not really sure that a C++ plugin for running inside Items in a loop will be faster, but my mind does say it should)
Nadav "Haliop" Rosenberg
Lets make the world great forever.
JasonPC
6
Years of Service
User Offline
Joined: 14th Apr 2015
Location: United Kingdom
Posted: 12th Feb 2021 19:52
My need is not normal @haliop787. The time taken to load and create a sprite/image is about 3-8 frames.
If this happens in the main loop, we see the app stutter.

My app is not a game, but I do want 60fps.

I did try using 720p images, but the time required was still consistently too long and frames were being skipped. When the code doesn't need a new image, I've plenty of overhead.

So, I'll be pre-loading them. Running the code, letting them leave the screen and the loading the next batch. I need to see how many images I can pre-load.
Not ideal, but for now, going multiple sprites is a complication I don't need. I'll need to slice the images "live" on a webserver (php/gd for that), save "image01, image02 etc. Then download them one at a time, create the sprite, built up the image probably 10 or so sprites, then bring them onto the screen (that's the easily part).

Login to post a reply

Server time is: 2021-07-31 09:41:23
Your offset time is: 2021-07-31 09:41:23