On Avoiding Delays when Preloading Web-based stimuli and changing their position/size


The purpose of this message is to inquire whether or not my current implementation properly avoids errors which cause delays and frame drops.

I am designing a web-based experiment involving 4 images which I preload at the beginning of the experiment by a line like the following :

image_preload = new visual.ImageStim({"win": win, "name": "image_preload", "units": "height", "image": image_path, "mask": undefined, "ori": 0, "pos": [1, 0], "size": [x,y], "color": [1, 1, 1], "colorSpace": "rgb", "opacity": 1, "flipHoriz": false, "flipVert": false, "texRes": 128, "interpolate": true, "depth": (- 3.0)});

During each trial, these same 4 images are displayed but the size and position change between trials and within each trial and I set autodraw to true between trials as well by lines like

(1) image_preload.setAutoDraw(true);

(2) image_preload.size = [new_size, new_size];

(3) image_preload.setPos([new_x, new_y]);

Will these 3 changes to the preloaded stimuli require enough time to cause frame drops? Approximately how quick will those above 3 operations occur? Will these 3 lines cause the image to be loaded excessively from the disk many times and cause timing issues?

I am looking to have a consistent response stimulus interval so I want my program to be fast enough so that when the previous trial ends at the beginning of one frame period, the next trial can begin by the end of that frame period.

Hi Ross,

With regard to the way you implement the stimulus presentation, I wouldn’t worry too much. With regard to differences between devices in stimulus timing accuracy and RT measurement accuracy, things get rather nuanced. This thread contains a rather extensive discussion on these topics: Is it possible to get the exact time of a flip in psychoJS

Best, Thomas

Thanks so much for your reply @thomas_pronk.

What function calls make the image load from disk again? My understanding is that the only command which causes a really expensive time cost is when we set or reset the image by a call like imagestim_object.setImage(“path”). Is this correct?

No. When you deploy a PsychoJS task, all stimuli are downloaded in advance from the webserver into internal memory. There are borderline cases where a stimulus does not get downloaded in advance, but when that happens, PsychoJS terminates the task with an error message.

Got it, so are there any function calls we really need to avoid when deploying a PsychoJS task if our goal is to avoid frame dropping during the duration of a routine and have smooth transitions between the iterations of a looping routine?

I’d recommend using as little code as possible; the code generated by the builder is aimed to be optimized for performance. Also, most timing accuracy studies used relatively simple operations; basically showing and hiding a single picture, so keeping the graphics simple is a good idea as well.