{"action":"created","issue":{"url":"https://api.github.com/repos/pfalcon/micropython/issues/13","repository_url":"https://api.github.com/repos/pfalcon/micropython","labels_url":"https://api.github.com/repos/pfalcon/micropython/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/pfalcon/micropython/issues/13/comments","events_url":"https://api.github.com/repos/pfalcon/micropython/issues/13/events","html_url":"https://github.com/pfalcon/micropython/issues/13","id":347276830,"node_id":"MDU6SXNzdWUzNDcyNzY4MzA=","number":13,"title":"Stack usage issues (due to inlining, etc.)","user":{"login":"pfalcon","id":500451,"node_id":"MDQ6VXNlcjUwMDQ1MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/500451?v=4","gravatar_id":"","url":"https://api.github.com/users/pfalcon","html_url":"https://github.com/pfalcon","followers_url":"https://api.github.com/users/pfalcon/followers","following_url":"https://api.github.com/users/pfalcon/following{/other_user}","gists_url":"https://api.github.com/users/pfalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/pfalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfalcon/subscriptions","organizations_url":"https://api.github.com/users/pfalcon/orgs","repos_url":"https://api.github.com/users/pfalcon/repos","events_url":"https://api.github.com/users/pfalcon/events{/privacy}","received_events_url":"https://api.github.com/users/pfalcon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-08-03T06:38:23Z","updated_at":"2018-08-05T19:46:48Z","closed_at":null,"author_association":"OWNER","body":"Master has issues with pretty big stack usage in some (many?) cases. This is due to fact that medern compilers prefer (only able to?) to allocate single big static stack frame for entire function at once, instead of growing/shrinking frame as they go thru various subblocks of a function. For example fo,\r\n\r\n~~~\r\nint i;\r\nif (rare_condition) {\r\n    char foo[1024];\r\n    ...\r\n}\r\n~~~\r\n\r\n1024 + 4 bytes of stack will be allocated always, even though, as suggested by the code, 1024 of those will be needed rarely. It would be smarter to allocate those 1024 only when control flow goes into the \"if\" body, but this seems to be the lost skill for modern gcc's and clang's. (Indeed, adjusting stack pointer in multiple places would take more code and more cycles, so they optimized it to allocate frame once at function start - ad absurdum, as the code above shows).\r\n\r\nThis is all aggravated by function inlining. As it's again the codesize saving measure, it happens not just for functions explicitly marked inline, but also may happen for static functions (for example, always would happen for a static function with a single caller).\r\n\r\nMany times, this is a bit less serious than completely grave, because other stack-hungry functions aren't called from such functions. But they always can be, e.g. an interrupt can occur when inside such stack-hoarding function, or it may deal with user (Python) type and call Python-level method, leading to really huge stack usage.\r\n"},"comment":{"url":"https://api.github.com/repos/pfalcon/micropython/issues/comments/410543244","html_url":"https://github.com/pfalcon/micropython/issues/13#issuecomment-410543244","issue_url":"https://api.github.com/repos/pfalcon/micropython/issues/13","id":410543244,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDU0MzI0NA==","user":{"login":"pfalcon","id":500451,"node_id":"MDQ6VXNlcjUwMDQ1MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/500451?v=4","gravatar_id":"","url":"https://api.github.com/users/pfalcon","html_url":"https://github.com/pfalcon","followers_url":"https://api.github.com/users/pfalcon/followers","following_url":"https://api.github.com/users/pfalcon/following{/other_user}","gists_url":"https://api.github.com/users/pfalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/pfalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfalcon/subscriptions","organizations_url":"https://api.github.com/users/pfalcon/orgs","repos_url":"https://api.github.com/users/pfalcon/repos","events_url":"https://api.github.com/users/pfalcon/events{/privacy}","received_events_url":"https://api.github.com/users/pfalcon/received_events","type":"User","site_admin":false},"created_at":"2018-08-05T19:46:48Z","updated_at":"2018-08-05T19:46:48Z","author_association":"OWNER","body":"Another thing is that -fomit-frame-pointer is apparently should be enabled. Again helps poor x86_32 to push less of ebp on the stack. But there could be peculiar arch for which -fomit-frame-pointer is not implemented, thus leading in build error.\r\n\r\n\r\n"}}
{"actor":{"display_login":"pfalcon"}}