X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB532385842C
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1712745271;
	bh=KcyiZz2WqUyooumDnTRRD/nd/jWMNLfBzra5bweaz6o=;
	h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=wpTnCYSle9VrVK8qd49HCTFYPKFaKMmm2cp2F5V6yf8eoMhJ5SA3K76CnpxJxHxu6
	 h9NOeHgJtxA6HSbji6QPH7YA5JZy417yMosm03Wk8U/SL9q6sOfl9GAKT+BWtXjB/Q
	 8ircVLo+bHBQaC1CsFXgllOhRxDNcQN9cx5aZw7M=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA0A83858D20
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA0A83858D20
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712745251; cv=none;
 b=Xvl3SMsNeI7v5dEXuTP0osnYMGaAGJ46CxIpb770uqbL12949a2e495I25Rfq6eh3/Uf1aHe6nZZ7kIkASW4wc3ZnEhbvUdIetHnX/zcDsAKvBWBt126TFGE8HKEM/NRAn6C9wMa8cZKWkskDnHi13KMtUgb5WAczZyE5LGZgD0=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1712745251; c=relaxed/simple;
 bh=m3voMasKjkwEYuNWYLug1c4Ikk9JxFPl6wy3G4p34a0=;
 h=Subject:To:From:Message-ID:Date:MIME-Version;
 b=Zt+txsoZAIcs80PCLPffe9iMbnXzTedBU8ueCjhmd1z0Q3GSDt9WxFf2sjqV6GU1P8HdvKhRS1SzRxB4J26+VN/x1nKYBX7RqbD4CkRO7avgUwyL5V/z6xScP1GPVBMBi6go3lIXyn0tMqWuyqPE45+k60jSBx1qV4vkqA2E7Dg=
ARC-Authentication-Results: i=1; server2.sourceware.org
Subject: Re: Cygwin a bit slow
To: cygwin@cygwin.com
References: <CAL8MddUVziE5+10=dANw_H8ySJRvhj-wZ857YqkcudmTZbJe+w@mail.gmail.com>
 <CA+kUOakQhTnCLdkhBCtiRn+G+0K4nQ-UCYN65044+D_OMsqfGg@mail.gmail.com>
 <CAL8MddWSvE8JHMSLzosREvWvzrJGGEEDi0cCQprL05SMGSsPqg@mail.gmail.com>
Message-ID: <df9abc70-6135-2871-c78f-aa87bc12f25b@t-online.de>
Date: Wed, 10 Apr 2024 12:34:02 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
 SeaMonkey/2.53.16
MIME-Version: 1.0
In-Reply-To: <CAL8MddWSvE8JHMSLzosREvWvzrJGGEEDi0cCQprL05SMGSsPqg@mail.gmail.com>
X-TOI-EXPURGATEID: 150726::1712745243-527FBD74-2996C9B9/0/0 CLEAN NORMAL
X-TOI-MSGID: 6332dcf5-79ad-4a75-83b7-5c4925260df3
X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, BODY_8BITS,
 FREEMAIL_FROM, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE,
 RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Christian Franke via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Christian Franke <Christian.Franke@t-online.de>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 43AAYYlJ781701

J M via Cygwin wrote:
> ...
>
> Specifically for this problem, I have investigated the problem and can be
> related to pipes and antivirus.
>
> Specifically
> while true
> do
> echo ABC | grep AAA
> done
>
> It makes the cpu of that antivirus go up.

This is as expected because malware scanners hook into Win32 API's 
CreateProcess*() calls which are also used by the fork()/exec() 
emulation of Cygwin. Each run of 'grep' above uses at least two 
CreateProcess*() calls.

This quick test shows how many 'date' commands could be run per second:

$ while :; do date +%s; done | uniq -c
...
      65 1712742865 <== Windows Defender off
      66 1712742866
      66 1712742867
      64 1712742868
      61 1712742869
      51 1712742870 <== Windows Defender turned on
      51 1712742871
      49 1712742872
      45 1712742873
      53 1712742874
      54 1712742875
...

The above could even slow down to 1-2 per second with certain malware 
scanners if expensive heuristics (which may also generate a lot of false 
positives, BTW) is enabled. So one problem is the lousy performance of 
CreateProcess*() calls. This is not Cygwin-specific but affects typical 
Cygwin use cases like shell scripts.

Using bash builtins in the above example speeds it up to ~21000/second 
on the same very old box:

$ while :; do printf '%(%s)T\n'; done | uniq -c

-- 
Regards,
Christian


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

