KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: ORDA Client-Server Optimization
PRODUCT: 4D | VERSION: 21 | PLATFORM: Mac & Win
Published On: January 20, 2026
The ORDA client-server optimization features in 4D reduce network traffic and enhance performance by intelligently learning which attributes are accessed in entity selections and caching them. This is ideal for remote datastores or client-server applications, minimizing data transfer by fetching only necessary attributes after an initial "learning" phase. Developers can reuse optimization contexts to skip learning and preconfigure them for deployed apps.



CreateData

var $i : Integer
var $employee : Object
var $lastnames; $firstnames; $departments; $cities; $states : Collection
var $lastname; $firstname; $department; $address : Text
var $salary : Real

ds.Employee.all().drop()

$lastnames:=New collection("Smith"; "Sanchez"; "Johnson"; "Smirnov"; "Lee"; "Singh"; "Schmidt"; "Suzuki"; "Brown"; "Santos"; "Taylor"; "Silva"; "Stewart"; "Sokolov"; "Davis"; "Wilson"; "Martinez"; "Anderson"; "Thomas"; "Jackson")
$firstnames:=New collection("John"; "Maria"; "Emily"; "Alex"; "David"; "Priya"; "Michael"; "Hiroshi"; "Sarah"; "Carlos"; "Jessica"; "Ana"; "James"; "Olga"; "Robert"; "Emma"; "Liam"; "Sophia"; "Noah"; "Olivia")
$departments:=New collection("Sales"; "Engineering"; "HR"; "IT"; "Marketing"; "Finance")
$cities:=New collection("New York"; "Los Angeles"; "Chicago"; "Seattle"; "Boston"; "Miami"; "Denver"; "San Francisco"; "Austin"; "Portland"; "Philadelphia"; "Atlanta"; "Detroit"; "Las Vegas"; "Phoenix")
$states:=New collection("NY"; "CA"; "IL"; "WA"; "MA"; "FL"; "CO"; "TX"; "OR"; "PA"; "GA"; "MI"; "NV"; "AZ")

For ($i; 1; 5000000)
   $employee:=ds.Employee.new()
  
   // Random selections
   $lastname:=$lastnames[Random%$lastnames.length] // Favor S-starting by choice of list
   $firstname:=$firstnames[Random%$firstnames.length]
   $department:=$departments[Random%$departments.length]
   $salary:=40000+(Random%40000)
   $address:=String(1+(Random%9999))+" "+$cities[Random%$cities.length]+" St, "+$cities[Random%$cities.length]+", "+$states[Random%$states.length]
  
   $employee.lastname:=$lastname
   $employee.firstname:=$firstname
   $employee.salary:=$salary
   $employee.department:=$department
   $employee.address:=$address
   $employee.save()
End for


Util_reuseQueryContext

#DECLARE($dataClassName : Text; $queryString : Text; $contextName : Text) \
  ->$data : Collection

var $settings : Object
var $sel : Object

$settings:=New object("context"; $contextName)

$sel:=ds[$dataClassName].query($queryString; $settings)

$data:=$sel.toCollection("lastname"; "firstname")

return $data



Example

var $data1; $data2 : Collection

$data1:=Util_reuseQueryContext("Employee"; "lastname = S@"; "shortList")

$data2:=Util_reuseQueryContext("Employee"; "lastname = Sm@"; "shortList")


For comparison: a query without context

var $selFull : Object
$selFull:=ds.Employee.query("lastname = S@")
var $dataFull : Collection
$dataFull:=$selFull.toCollection("lastname"; "firstname"; "salary"; "address")