@@ -25,8 +25,8 @@ performance.
25
25
Boolean Available { get ; };
26
26
27
27
// This property has one value for the lifetime of the object so we mark it
28
- // readonly to improve wv2winrt performance.
29
- [ corewebview2readonly ]
28
+ // memoizable to improve runtime performance.
29
+ [ memoizable ]
30
30
String Model { get ; };
31
31
32
32
// ...
@@ -38,16 +38,34 @@ performance.
38
38
``` c# (but really MIDL3)
39
39
namespace Microsoft .Web .WebView2 .Core
40
40
{
41
- /// You can use the CoreWebView2ReadOnly attribute on a runtimeclass property
42
- /// definition in MIDL3 if the property value doesn't change for the lifetime
43
- /// of its object. When an object is projected into JavaScript via
41
+ /// You can use the `memoizable` attribute on a runtimeclass property
42
+ /// or runtimeclass method to indicate that the property value or
43
+ /// method return value can be cached.
44
+ ///
45
+ /// You can apply it to an instance property if the property
46
+ /// value doesn't change for the lifetime of its object instance.
47
+ /// You can apply it to a static property if the property value
48
+ /// doesn't change for the lifetime of the process.
49
+ /// You can apply it to an instance method if when the method is called
50
+ /// with the same parameters it always returns the same value for the
51
+ /// lifetime of its object instance.
52
+ /// You can apply it to a static method if when the method is called
53
+ /// with the same parameters it always returns the same value for the
54
+ /// lifetime of the process.
55
+ /// If the property type or the method return type is an object, the property
56
+ /// value must be the same object by reference or the method must return the
57
+ /// same object by reference in order to be memoizable. Merely returning an
58
+ /// equivalent but different object is not sufficient to be memoizable.
59
+ /// Similarly, a method call having the same parameters means the same object
60
+ /// references and not equivalent but different objects.
61
+ ///
62
+ /// When an object is projected into JavaScript via
44
63
/// `CoreWebView2.AddHostObjectToScript`, WebView2 will cache property values
45
64
/// marked with this attribute. This can potentially improve performance by
46
- /// reducing the number of cross-process calls to obtain the latest value of
47
- /// the property.
48
- [attributeusage (target_property )]
49
- [attributename (" corewebview2readonly" )]
50
- attribute CoreWebView2ReadOnlyAttribute
65
+ /// reducing the number of cross-process calls to obtain the latest value.
66
+ [attributeusage (target_property , target_method )]
67
+ [attributename (" memoizable" )]
68
+ attribute MemoizableAttribute
51
69
{
52
70
}
53
71
}
@@ -56,14 +74,14 @@ namespace Microsoft.Web.WebView2.Core
56
74
# Appendix
57
75
58
76
Names considered for the attribute:
59
- * ** Cacheable** : Caching is what WebView2 will do with the property rather than describing
60
- an aspect of the runtimeclass property.
77
+ * ** Cacheable**
61
78
* ** ReadOnly** : Similar to C#'s readonly keyword which indicates a value won't change (once
62
- initialized). A more familiar term to end developers than 'immutable'. It does
63
- convey that the caller can't set it, but does it also convey that the implementer also
64
- cannot change the value?
65
- * ** Immutable** : Perhaps more explicit than readonly that the implementer also cannot
66
- change the value, but perhaps less familiar of a term.
79
+ initialized). But does not convey that the implementer cannot change the value.
80
+ * ** Immutable** : Similar to readonly
81
+ * ** Const** : Does a better job indicating that the value does not change even by the
82
+ implementer.
83
+ * ** Memoizable** : A broader term than cacheable that also applies to methods but more specific
84
+ than cacheable in that it better defines the kind of caching.
67
85
68
86
For the sample code, the only code you have to write is applying the attribute to the
69
87
property. The only effect this has is to potentially improve performance so there's no other
0 commit comments