On 2011-02-06 4:02 AM, Philip Prindeville wrote:
> On 2/5/11 9:49 AM, Felix Fietkau wrote:
>> On 2011-02-05 12:26 PM, Bastian Bittorf wrote:
>>> Some weeks ago, i started (undesired) a discussion[1,2]
>>> about how and why i think the base-files should get
>>> a refurbishment. I send several patches as a proposal,
>>> but it was not possible to apply them - the reasons are:
>>>
>>> - the code changed nearly nothing, only the style
>>> - some people mentioned, that the old code was not good,
>>>    but it worked since years and changes in base are risky
>>> - it is not clear, if lowmem-targets are part of openwrt
>>>    (most of the patches uses lower mem and are faster)
>>> - there is no official coding style, that enforces the
>>>    use of specific ways how to do things
>>> - i mixed the reasons, why i wrote the new code
>>>
>>> Here some words about this:
>>>
>>> I like openwrt. There are many concepts i want to see
>>> in other distros. I'm not satisfied with many scripts
>>> and the way how people make a solution. Ofcourse this
>>> is my personal opinion, but there are good reasons to
>>> speak loud:
>>>
>>> - clean code (not obfuscated)
>>>
>>> This should be the most imported thing.
>>> It helps to debug.
>>> It lowers the entry-border.
>>> It makes it easier to change the code and do refactoring.
>>> (i have some ideas to modularize the functions/files, at the
>>> moment we often include files which we don't need)
>>>
>>> It does NOT help to make a oneliner and 1000 users asks
>>> themself: what does THIS line? [3]
>>>
>>> But while we are at it:
>>> - don't fork, if not needed. examples from /etc/init.d/compache:
>>>
>>> [ "`cat /proc/swaps | grep 'ramzswap0'`" != "" ]&&  swapoff /dev/ramzswap0
>>>
>>> better use:
>>> fgrep -q "ramzswap0" /proc/swaps || ...
>> I fully agree with changes like this.
>>
>>> - use function_names to say what you want to do
>>> - use better shell builtins, instead of invoking another language
>>>    (e.g. awk, sed, lua) - only if there is no other option
>> I disagree with that. awk and sed are part of most typical shell
>> scripts, they've been around for ages and if awk and sed make something
>> expressible in one line instead of 10 without being unnecessarily
>> complex, then I consider that an improvement over writing weird
>> while/read/case loops.
>>
>>> - using of shell builtins, leads to lower mem usage and are (mostly) faster
>>>
>>> In the first discussion, i explained that awk is big and should not
>>> be in base-files. During experiments it turned out, that these are only
>>> some kilobytes. But the real reasons are explained above.
>> I think many of these scripts are simply prototypes - trying to evolve
>> them to better suit devices with 8 MB RAM is mostly a pointless
>> excercise, as many of them will be replaced with compact and much more
>> efficent c-code soon-ish. We will integrate new infrastructure for
>> starting/stopping/monitoring services and for generating config files
>> soon, which could work for even complex services without writing any
>> complex shell scripts - simply by having a proper description language.
> 
> That's true, but at the same time the cost of a fork()/exec() pair
> is non-trivial, not to mention all of the cacheline misses that will incur.
> If you can keep things in the same process space, that's a big win.
> 
> The "hairiness" of the scripting can be abstracted away by using
> function wrappers in shell.
awk/sed calls do not result in an exec() because they're handled by
busybox internally. All it does is a fork, and thanks to copy-on-write,
most of the memory stays shared.

Not that I don't agree with the general goal of making things more
efficient, but as mentioned earlier, a lot of this code will be replaced
with non-shell stuff anyway.

- Felix
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to