From b439c9fcdc390d6f1e8ce0da4acf575dae65a865 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 14 Jun 2021 18:54:47 -0700 Subject: [PATCH] Update performance.md Restore the original sentence with tweaks; this seems like better wording since it highlights the importance of knowing the field name at compile time, no matter the notation. --- docs/_pages/performance.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_pages/performance.md b/docs/_pages/performance.md index 2158bda..076ce61 100644 --- a/docs/_pages/performance.md +++ b/docs/_pages/performance.md @@ -45,6 +45,7 @@ Table access for field lookup is optimized in Luau using a mechanism that blends As a result, field access can be very fast in Luau, provided that: +- The field name is known at compile time. To make sure this is the case, `table.field` notation is recommended, although the compiler will also optimize `table["field"]` when the expression is known to be a constant string. - The field access doesn't use metatables. The fastest way to work with tables in Luau is to store fields directly inside the table, and store methods in the metatable (see below); access to "static" fields in classic OOP designs is best done through `Class.StaticField` instead of `object.StaticField`. - The object structure is usually uniform. While it's possible to use the same function to access tables of different shape - e.g. `function getX(obj) return obj.x end` can be used on any table that has a field `"x"` - it's best to not vary the keys used in the tables too much, as it defeats this optimization.