{"action":"created","comment":{"url":"https://api.github.com/repos/weld/weld.github.io/pulls/comments/84689940","pull_request_review_id":5443907,"id":84689940,"diff_hunk":"@@ -0,0 +1,184 @@\n+---\n+layout: news\n+title: Weld Tip 3 - Performance\n+author: Martin Kouba\n+priority: 1\n+change_frequency: weekly\n+excerpt: Explore various aspects of CDI/Weld performance.\n+desc: Weld Tip 3 - Performance\n+tags: [tips]\n+---\n+:linkattrs:\n+:toc: macro\n+:toc-title: Contents\n+:icons: font\n+\n+toc::[]\n+\n+In this article we're going to dive into various performance aspects of CDI applications.\n+As you've probably noticed performance testing is sometimes tricky.\n+First of all, it's difficult to create a meaningful benchmark.\n+One should understand the JVM specifics (the need for warmup, garbage collection, JVM settings, etc.) and also use appropriate tools (e.g. link:http://openjdk.java.net/projects/code-tools/jmh/[JMH, window=\"_blank\"] for microbenchmarks) appropriately.\n+And still this is usually not enough.\n+One should also run the test in a relevant context (data, load, etc.).\n+Performance specialists also say that's it's good to avoid premature optimizations but keep performance aspects in mind when tuning the \"final\" code.\n+But all these considerations are out of scope of this article.\n+Let's go through several areas where CDI affects the performance of your application and discuss the possibilities.\n+\n+== Bootstrap\n+\n+During bootstrap the overhead of a framework should be minimal so that it does not _slow down_ the application startup and also does not eat all the memory available.\n+However, CDI needs to do all that magic behind the scenes - read annotations, build and validate metadata, etc.\n+The following sections describe what could be done minimize the impact.\n+\n+=== Discovery mode\n+\n+In CDI 1.0 there was only one _\"discovery mode\"_.\n+How does it work?\n+Simply put: find all bean archives (containing `beans.xml`), discover and process all the found classes (identify beans, etc.).\n+Needless to say, this might be a performance problem for large applications with thousands of classes.\n+In CDI 1.1+ we call this mode `all` and a bean archive with this mode is called *EXPLICIT*.\n+Since CDI 1.1+ a new discovery mode - `annotated` - can be used.\n+The difference is that if this mode is used only classes with a link:http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#bean_defining_annotations[bean defining annotation, window=\"_blank\"] are considered.\n+In other words, a component must be explicitly designated.\n+A bean archive with this mode is called *IMPLICIT*.\n+To make things a little bit more complicated, an implicit bean archive does not have to contain a `beans.xml` file at all.\n+One class with a bean defining annotation or a session bean is enough.\n+\n+Implicit bean archive has pros and cons:\n+\n+* icon:thumbs-o-up[] saves a lot of memory if an archive contains a lot of classes which should NOT become beans (the container does not have to store the metadata)\n+* icon:thumbs-o-up[] speeds up the bootstrap (the container does not have to process all the types, fire events like `ProcessBean`, etc.)\n+* icon:thumbs-down[] does not fire `ProcessAnnotatedType` for all types from the bean archive; this breaks some extensions (e.g. `MessageBundleExtension` from DeltaSpike)\n+* icon:thumbs-down[] does not pick up `javax.inject.Singleton` beans (it's not a bean defining annotation)\n+\n+*CONCLUSION*: If possible, use the `annotated` discovery mode.\n+\n+TIP: Most Weld-based runtimes allow to suppress implicit bean archives without `beans.xml`, i.e. require the `beans.xml` file in bean archives so that it's not necessary to scan all the parts of the application. See also link:/documentation/#4[FAQ].\n+\n+TIP: If it's not possible to use `annotated` mode, you can try a Weld-specific feature to conserve memory used: link:http://docs.jboss.org/weld/reference/latest/en-US/html/configure.html#veto-types-without-bean-defining-annotation[Veto types without bean defining annotation, window=\"_blank\"].\n+A similar solution is going to be standardized in CDI 2.0 (see also link:https://issues.jboss.org/browse/CDI-420[CDI-420, window=\"_blank\"]).\n+\n+=== Extensions\n+\n+CDI portable extensions are essential integration points.\n+And users love integrated technologies.\n+However, the more extensions the more work must be done during bootstrap.\n+For example, there is a `ProcessAnnotatedType` container lifecycle event.\n+This event is fired:\n+\n+* for every type in an EXPLICIT bean archive,\n+* for every session bean and every type with a bean defining annotation in an IMPLICIT bean archive.\n+\n+The delivery might be restricted by means of type arguments, e.g. for observer `void observeNumbers(@Observes ProcessAnnotatedType<Number> event)` an extension will be notified for every class assignable to `Number`.\n+However, if you do `<T> void observe(@Observes ProcessAnnotatedType<T> event)` your extension will be notified for every class that is discovered.\n+Now if we have an application with one EXPLICIT bean archive with 2000 classes, then a specific observer method on such extesion will be called 1000x.","path":"news/2016-10-26-tip3-performance.asciidoc","position":75,"original_position":75,"commit_id":"3a48703bc684f3e6a72ca235cddb4606fc271923","original_commit_id":"3a48703bc684f3e6a72ca235cddb4606fc271923","user":{"login":"manovotn","id":4181235,"avatar_url":"https://avatars.githubusercontent.com/u/4181235?v=3","gravatar_id":"","url":"https://api.github.com/users/manovotn","html_url":"https://github.com/manovotn","followers_url":"https://api.github.com/users/manovotn/followers","following_url":"https://api.github.com/users/manovotn/following{/other_user}","gists_url":"https://api.github.com/users/manovotn/gists{/gist_id}","starred_url":"https://api.github.com/users/manovotn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manovotn/subscriptions","organizations_url":"https://api.github.com/users/manovotn/orgs","repos_url":"https://api.github.com/users/manovotn/repos","events_url":"https://api.github.com/users/manovotn/events{/privacy}","received_events_url":"https://api.github.com/users/manovotn/received_events","type":"User","site_admin":false},"body":"`1000x` , I may be a bit tired, but shouldn't this be `2000x`?","created_at":"2016-10-24T13:44:13Z","updated_at":"2016-10-24T13:44:13Z","html_url":"https://github.com/weld/weld.github.io/pull/38#discussion_r84689940","pull_request_url":"https://api.github.com/repos/weld/weld.github.io/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/comments/84689940"},"html":{"href":"https://github.com/weld/weld.github.io/pull/38#discussion_r84689940"},"pull_request":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/weld/weld.github.io/pulls/38","id":90597624,"html_url":"https://github.com/weld/weld.github.io/pull/38","diff_url":"https://github.com/weld/weld.github.io/pull/38.diff","patch_url":"https://github.com/weld/weld.github.io/pull/38.patch","issue_url":"https://api.github.com/repos/weld/weld.github.io/issues/38","number":38,"state":"open","locked":false,"title":"Weld tip - performance","user":{"login":"mkouba","id":913004,"avatar_url":"https://avatars.githubusercontent.com/u/913004?v=3","gravatar_id":"","url":"https://api.github.com/users/mkouba","html_url":"https://github.com/mkouba","followers_url":"https://api.github.com/users/mkouba/followers","following_url":"https://api.github.com/users/mkouba/following{/other_user}","gists_url":"https://api.github.com/users/mkouba/gists{/gist_id}","starred_url":"https://api.github.com/users/mkouba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkouba/subscriptions","organizations_url":"https://api.github.com/users/mkouba/orgs","repos_url":"https://api.github.com/users/mkouba/repos","events_url":"https://api.github.com/users/mkouba/events{/privacy}","received_events_url":"https://api.github.com/users/mkouba/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-24T11:55:12Z","updated_at":"2016-10-24T13:54:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"66ebfb4f91775a03ba65ac34a83f83f5bfe732ef","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/weld/weld.github.io/pulls/38/commits","review_comments_url":"https://api.github.com/repos/weld/weld.github.io/pulls/38/comments","review_comment_url":"https://api.github.com/repos/weld/weld.github.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/weld/weld.github.io/issues/38/comments","statuses_url":"https://api.github.com/repos/weld/weld.github.io/statuses/3a48703bc684f3e6a72ca235cddb4606fc271923","head":{"label":"mkouba:tip-perf","ref":"tip-perf","sha":"3a48703bc684f3e6a72ca235cddb4606fc271923","user":{"login":"mkouba","id":913004,"avatar_url":"https://avatars.githubusercontent.com/u/913004?v=3","gravatar_id":"","url":"https://api.github.com/users/mkouba","html_url":"https://github.com/mkouba","followers_url":"https://api.github.com/users/mkouba/followers","following_url":"https://api.github.com/users/mkouba/following{/other_user}","gists_url":"https://api.github.com/users/mkouba/gists{/gist_id}","starred_url":"https://api.github.com/users/mkouba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkouba/subscriptions","organizations_url":"https://api.github.com/users/mkouba/orgs","repos_url":"https://api.github.com/users/mkouba/repos","events_url":"https://api.github.com/users/mkouba/events{/privacy}","received_events_url":"https://api.github.com/users/mkouba/received_events","type":"User","site_admin":false},"repo":{"id":29920678,"name":"weld.github.io","full_name":"mkouba/weld.github.io","owner":{"login":"mkouba","id":913004,"avatar_url":"https://avatars.githubusercontent.com/u/913004?v=3","gravatar_id":"","url":"https://api.github.com/users/mkouba","html_url":"https://github.com/mkouba","followers_url":"https://api.github.com/users/mkouba/followers","following_url":"https://api.github.com/users/mkouba/following{/other_user}","gists_url":"https://api.github.com/users/mkouba/gists{/gist_id}","starred_url":"https://api.github.com/users/mkouba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkouba/subscriptions","organizations_url":"https://api.github.com/users/mkouba/orgs","repos_url":"https://api.github.com/users/mkouba/repos","events_url":"https://api.github.com/users/mkouba/events{/privacy}","received_events_url":"https://api.github.com/users/mkouba/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mkouba/weld.github.io","description":"Weld website","fork":true,"url":"https://api.github.com/repos/mkouba/weld.github.io","forks_url":"https://api.github.com/repos/mkouba/weld.github.io/forks","keys_url":"https://api.github.com/repos/mkouba/weld.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mkouba/weld.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mkouba/weld.github.io/teams","hooks_url":"https://api.github.com/repos/mkouba/weld.github.io/hooks","issue_events_url":"https://api.github.com/repos/mkouba/weld.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/mkouba/weld.github.io/events","assignees_url":"https://api.github.com/repos/mkouba/weld.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/mkouba/weld.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/mkouba/weld.github.io/tags","blobs_url":"https://api.github.com/repos/mkouba/weld.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mkouba/weld.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mkouba/weld.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/mkouba/weld.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mkouba/weld.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/mkouba/weld.github.io/languages","stargazers_url":"https://api.github.com/repos/mkouba/weld.github.io/stargazers","contributors_url":"https://api.github.com/repos/mkouba/weld.github.io/contributors","subscribers_url":"https://api.github.com/repos/mkouba/weld.github.io/subscribers","subscription_url":"https://api.github.com/repos/mkouba/weld.github.io/subscription","commits_url":"https://api.github.com/repos/mkouba/weld.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/mkouba/weld.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/mkouba/weld.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/mkouba/weld.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/mkouba/weld.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/mkouba/weld.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mkouba/weld.github.io/merges","archive_url":"https://api.github.com/repos/mkouba/weld.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mkouba/weld.github.io/downloads","issues_url":"https://api.github.com/repos/mkouba/weld.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/mkouba/weld.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/mkouba/weld.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/mkouba/weld.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mkouba/weld.github.io/labels{/name}","releases_url":"https://api.github.com/repos/mkouba/weld.github.io/releases{/id}","deployments_url":"https://api.github.com/repos/mkouba/weld.github.io/deployments","created_at":"2015-01-27T15:39:19Z","updated_at":"2015-03-10T13:00:50Z","pushed_at":"2016-10-24T11:33:22Z","git_url":"git://github.com/mkouba/weld.github.io.git","ssh_url":"git@github.com:mkouba/weld.github.io.git","clone_url":"https://github.com/mkouba/weld.github.io.git","svn_url":"https://github.com/mkouba/weld.github.io","homepage":null,"size":1244,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"weld:devel","ref":"devel","sha":"99fa5f176c2cf3bfbdbb1c668451af40461d0b14","user":{"login":"weld","id":331033,"avatar_url":"https://avatars.githubusercontent.com/u/331033?v=3","gravatar_id":"","url":"https://api.github.com/users/weld","html_url":"https://github.com/weld","followers_url":"https://api.github.com/users/weld/followers","following_url":"https://api.github.com/users/weld/following{/other_user}","gists_url":"https://api.github.com/users/weld/gists{/gist_id}","starred_url":"https://api.github.com/users/weld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weld/subscriptions","organizations_url":"https://api.github.com/users/weld/orgs","repos_url":"https://api.github.com/users/weld/repos","events_url":"https://api.github.com/users/weld/events{/privacy}","received_events_url":"https://api.github.com/users/weld/received_events","type":"Organization","site_admin":false},"repo":{"id":10821387,"name":"weld.github.io","full_name":"weld/weld.github.io","owner":{"login":"weld","id":331033,"avatar_url":"https://avatars.githubusercontent.com/u/331033?v=3","gravatar_id":"","url":"https://api.github.com/users/weld","html_url":"https://github.com/weld","followers_url":"https://api.github.com/users/weld/followers","following_url":"https://api.github.com/users/weld/following{/other_user}","gists_url":"https://api.github.com/users/weld/gists{/gist_id}","starred_url":"https://api.github.com/users/weld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weld/subscriptions","organizations_url":"https://api.github.com/users/weld/orgs","repos_url":"https://api.github.com/users/weld/repos","events_url":"https://api.github.com/users/weld/events{/privacy}","received_events_url":"https://api.github.com/users/weld/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/weld/weld.github.io","description":"Weld website","fork":false,"url":"https://api.github.com/repos/weld/weld.github.io","forks_url":"https://api.github.com/repos/weld/weld.github.io/forks","keys_url":"https://api.github.com/repos/weld/weld.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weld/weld.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weld/weld.github.io/teams","hooks_url":"https://api.github.com/repos/weld/weld.github.io/hooks","issue_events_url":"https://api.github.com/repos/weld/weld.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/weld/weld.github.io/events","assignees_url":"https://api.github.com/repos/weld/weld.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/weld/weld.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/weld/weld.github.io/tags","blobs_url":"https://api.github.com/repos/weld/weld.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weld/weld.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weld/weld.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/weld/weld.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weld/weld.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/weld/weld.github.io/languages","stargazers_url":"https://api.github.com/repos/weld/weld.github.io/stargazers","contributors_url":"https://api.github.com/repos/weld/weld.github.io/contributors","subscribers_url":"https://api.github.com/repos/weld/weld.github.io/subscribers","subscription_url":"https://api.github.com/repos/weld/weld.github.io/subscription","commits_url":"https://api.github.com/repos/weld/weld.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/weld/weld.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/weld/weld.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/weld/weld.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/weld/weld.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/weld/weld.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weld/weld.github.io/merges","archive_url":"https://api.github.com/repos/weld/weld.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weld/weld.github.io/downloads","issues_url":"https://api.github.com/repos/weld/weld.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/weld/weld.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/weld/weld.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/weld/weld.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weld/weld.github.io/labels{/name}","releases_url":"https://api.github.com/repos/weld/weld.github.io/releases{/id}","deployments_url":"https://api.github.com/repos/weld/weld.github.io/deployments","created_at":"2013-06-20T14:18:26Z","updated_at":"2016-04-21T08:03:23Z","pushed_at":"2016-10-24T11:55:12Z","git_url":"git://github.com/weld/weld.github.io.git","ssh_url":"git@github.com:weld/weld.github.io.git","clone_url":"https://github.com/weld/weld.github.io.git","svn_url":"https://github.com/weld/weld.github.io","homepage":null,"size":3137,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":1,"forks":9,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/38"},"html":{"href":"https://github.com/weld/weld.github.io/pull/38"},"issue":{"href":"https://api.github.com/repos/weld/weld.github.io/issues/38"},"comments":{"href":"https://api.github.com/repos/weld/weld.github.io/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/weld/weld.github.io/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/weld/weld.github.io/statuses/3a48703bc684f3e6a72ca235cddb4606fc271923"}}}}
{"actor":{"display_login":"manovotn"}}