Skip to content

Commit 10e26e6

Browse files
committed
SPR-6123: doc update on writing good pointcuts (should include a within())
1 parent 71a0453 commit 10e26e6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

spring-framework-reference/src/aop.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,35 @@ public class SystemArchitecture {
892892
</listitem>
893893
</itemizedlist>
894894
</section>
895+
<section id="writing-good-pointcuts">
896+
<title>Writing good pointcuts</title>
897+
898+
<para>During compilation, AspectJ processes pointcuts in order to try and optimize matching performance. Examining code
899+
and determining if each join point matches (statically or dynamically) a given pointcut is a costly process. (A dynamic
900+
match means the match cannot be fully determined from static analysis and a test will be placed in the code to
901+
determine if there is an actual match when the code is running). On first encountering a pointcut declaration,
902+
AspectJ will rewrite it into an optimal form for the matching process. What does this mean? Basically pointcuts
903+
are rewritten in DNF (Disjunctive Normal Form) and the components of the pointcut are sorted such that those
904+
components that are cheaper to evaluate are checked first. This means you do not have to worry about understanding
905+
the performance of various pointcut designators and may supply them in any order in a pointcut declaration.</para>
906+
907+
<para>However, AspectJ can only work with what it is told, and for optimal performance of matching you should
908+
think about what they are trying to achieve and narrow the search space for matches as much as possible in the
909+
definition. The existing designators naturally fall into one of three groups: kinded, scoping and context:</para>
910+
<itemizedlist>
911+
<listitem><para>Kinded designators are those which select a particular kind of join point. For example: execution, get, set, call, handler</para></listitem>
912+
<listitem><para>Scoping designators are those which select a group of join points of interest (of probably many kinds). For example: within, withincode</para></listitem>
913+
<listitem><para>Contextual designators are those that match (and optionally bind) based on context. For example: this, target, @annotation</para></listitem>
914+
</itemizedlist>
915+
916+
<para>A well written pointcut should try and include at least the first two types (kinded and scoping), whilst
917+
the contextual designators may be included if wishing to match based on join point context, or bind that context
918+
for use in the advice. Supplying either just a kinded designator or just a contextual designator will work but
919+
could affect weaving performance (time and memory used) due to all the extra processing and analysis. Scoping
920+
designators are very fast to match and their usage means AspectJ can very quickly dismiss groups of
921+
join points that should not be further processed - that is why a good pointcut should always include
922+
one if possible.</para>
923+
</section>
895924
</section>
896925

897926
<section id="aop-advice">

spring-framework-reference/src/spring-framework-reference.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@
107107
<firstname>Tareq</firstname>
108108
<surname>Abedrabbo</surname>
109109
</author>
110+
<author>
111+
<firstname>Andy</firstname>
112+
<surname>Clement</surname>
113+
</author>
110114
</authorgroup>
111115
<copyright>
112116
<year>2004-2009</year>
113117
<holder>Rod Johnson, Juergen Hoeller, Keith Donald, Colin Sampaleanu, Rob Harrop, Alef Arendsen, Thomas Risberg, Darren Davison,
114118
Dmitriy Kopylenko, Mark Pollack, Thierry Templier, Erwin Vervaet, Portia Tung, Ben Hale, Adrian Colyer, John Lewis,
115-
Costin Leau, Mark Fisher, Sam Brannen, Ramnivas Laddad, Arjen Poutsma, Chris Beams, Tareq Abedrabbo
119+
Costin Leau, Mark Fisher, Sam Brannen, Ramnivas Laddad, Arjen Poutsma, Chris Beams, Tareq Abedrabbo, Andy Clement
116120
</holder>
117121
</copyright>
118122
<legalnotice>

0 commit comments

Comments
 (0)