Cloud Vision API looks slower only for first time

161 views
Skip to first unread message

Yusuke Yonenaga

unread,
Dec 10, 2021, 12:29:09 AM12/10/21
to cloud-vision-discuss
When I perform Vision API as trial, it always looks slow only for 1st time.
Does someone know why?

1st: 2.673ms
2nd: 0.126ms
3rd: 0.111ms
4th: 0.117ms
5th: 0.183ms
6ht: 0.218ms
7th: 0.192ms

Each time, different (but almost same size) picture was used.
It's done by script in succession.

Carlos Clement Bellido

unread,
Dec 10, 2021, 3:33:34 AM12/10/21
to cloud-vision-discuss

Hi! Possibly you’re facing some warmup or caching that boosts performance of subsequent calls, can you give more details about this behavior?

  • When is a call a "first call”, when the program first runs?

  • When you ran the script, in each run was the same picture used or you changed the picture in each petition? In other words:

    • 1st: 2.673ms – This image is the same in the next tests (2nd, 3rd, 4th…) or do you change the picture only when the script starts?

    • 2nd: 0.126ms

    • 3rd: 0.111ms

    • 4th: 0.117ms

    • 5th: 0.183ms

    • 6ht: 0.218ms

    • 7th: 0.192ms

Yusuke Yonenaga

unread,
Dec 13, 2021, 4:58:33 AM12/13/21
to cloud-vision-discuss
Hi, Thank you for reply !!

>Possibly you’re facing some warmup or caching that boosts performance of subsequent calls, >can you give more details about this behavior? --> If that's the case, if our system use Vision API as background, it always takes more than 2 second?
     < Use Case >
     1 system user calls Vision API (for license card text detection) only once in their registaration process.

  • When you ran the script, in each run was the same picture used or you changed the picture in each petition? --> I changed picture for each time (means, defferent picture was used for 1st/2nd/3rd... but each file size is almost same.)

    • 1st: 2.673ms – This image is the same in the next tests (2nd, 3rd, 4th…) or do you change the picture only when the script starts? --> No, image used for 1st and one for 2nd are different.

    • 2nd: 0.126ms

    • 3rd: 0.111ms

    • 4th: 0.117ms

    • 5th: 0.183ms

    • 6ht: 0.218ms

    • 7th: 0.192ms



    The below is script used for trial, just FYI.
    Script perform Vision API  subsequently based on files in the directory.
    And time count starts just before using API.

    ---------------------------------------------------------------------------------------------------
    var fs = require('fs'); var path = require('path'); Folder="./images/mitree/" output="./results/mitree/" const vision = require("@google-cloud/vision"); const client = new vision.ImageAnnotatorClient({ keyFilename : "./cloudvision-333803-XXXXXX.json" }) fs.readdirSync(Folder).forEach((file) => { var filename = file.split(".")[0]; filename=filename var txtfilename=output+filename+".txt" console.time(); client .textDetection(Folder+filename+".jpg") .then(results => { const detections = results[0].textAnnotations; fs.writeFile(txtfilename, detections[0].description, function (err) { if (err) return console.log(err); }); }) .catch(err => { console.error('ERROR:', err); }); console.timeEnd(); })



    2021年12月10日金曜日 17:33:34 UTC+9 clement...@google.com:

    Brendan Lundy

    unread,
    Dec 13, 2021, 12:08:18 PM12/13/21
    to cloud-vision-discuss
    The client library uses ADC: https://google.aip.dev/auth/4110  The client library lazily gets the token when the first request is attempted. After the first request, the token is automatically refreshed when near expiration. The time of your first request includes time to get the first token.
    Reply all
    Reply to author
    Forward
    0 new messages