I ran into a serious performance problem with 4D Objects and figured I’d 
mention it so others may be able to avoid the scenario. I am consuming an API 
returning JSON. Some endpoints return an object with properties, and some 
return an array of objects. To present a consistent interface in the code, I 
decided to wrap the arrays in an object with a root key. However, if once you 
have an object with more than around 500 object elements in an array, accessing 
the object gets extremely slow. By the time you hit 1000 elements the object is 
nearly unusable. Even getting the single property name and type from the root 
level can take 3+ seconds. OB GET ARRAY and OB SET ARRAY take multiple seconds 
as well. Each object had maybe 20 properties with 10 of them being small 
sub-objects, but still, 1000 isn’t very many. Putting a couple thousand objects 
like this into an object array doesn’t cause any problems by itself, so it’s 
not something that just happens after a certain number of objects is generated, 
it’s something that happens when the array is put into an object. 

My initial implementation following the API’s paging was a nice simple 
recursive algorithm, but taking multiple minutes to unroll 15 pages (100 items 
each) into a single object was kind of ridiculous, so I had to work around it 
by using a loop and accumulating an object array.

Also, does 4D still not have built-in URL encode/decode yet? Did I miss it? I 
did spend a while looking through the documentation, but if it’s there I can’t 
find it. Built-in URL parsing into an object would be nice too, especially if 
it handled the array/subobject notation that PHP and Rails parse by default. 
The sad part is that quite a few have probably already written that very thing, 
and I probably will as well when I finally need it (already wrote basic URL 
query parameter parsing into an object, and vice versa), but it’s so difficult 
to extract/share/use code modules that there’s no 
RubyGems/CocoaPods/CPAN/NPM/PyPi/Composer equivalent for 4D.

TL;DR: don’t put object arrays of more than a couple hundred elements into an 
object if you don’t like looking at the spinning wheel of death. And definitely 
don’t expand an object property in the debugger that has an object array of 
800+ elements unless it’s time to break for multiple drinks.

Jim Crate

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to